PHPで外部変数の文字コードを変換する。
shift-jisでgetした変数をEUC-JPに変換する時の[mb_convert_encoding]の覚え書き
$data =mb_convert_encoding($data,"EUC-JP" ,"SJIS" ); ↑ ↑ ↑ 元の変数 [コレに変更] [コレを]
[k]id
2008年8月22日
shift-jisでgetした変数をEUC-JPに変換する時の[mb_convert_encoding]の覚え書き
$data =mb_convert_encoding($data,"EUC-JP" ,"SJIS" ); ↑ ↑ ↑ 元の変数 [コレに変更] [コレを]
2008年7月28日
最近APIを利用し、コンテンツ生成をしているのですが、
今度はWikipedia APIを利用しwikiの情報を引っ張ってきたいと思います。
このサービスの詳細はWikipedia APIを見て下さい。
出力形式は
・XML
・RSS
・JSON
・PHP
・HTML
・TSV
・ JavaScript
で吐き出せるみたいです。
使い方は
http://wikipedia.simpleapi.net/api?keyword=ここに検索したいキーワード&output=xml
2008年7月19日
WordPressで各ページのタグを元に関連した動画をYouTubeから表示できないかと思い、YouTube API を利用て、サイドバー表示用のソースを書いてみました。忘れてしまうといけないので覚え書き。。
define(“LOGID”,”xxx-xxxxxx”); のxの所に
YouTube API で発行されたIDを入力。
<!-- begin youtube --> YouTube動画表示<br> <div> if (have_posts()) : while (have_posts()) : the_post(); $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { $samples[] = $tag->name; } } endwhile; endif; define("IDS",$samples[0]); define("LOGID","xxx-xxxxxx"); //←ここにデベロッパーIDを記入 function getlyoutube(){ $url = "http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=".LOGID."&tag=".IDS."&page=1&per_page=3"; $xmldata = simplexml_load_file($url); return($xmldata); } <dl> $data = getlyoutube(); foreach($data->video_list->video as $item){ echo '<dt><a href="'.$item->url.'"><img width=65 height=49 src="'.$item->thumbnail_url.'"></a></dt>'; echo '<dd><h4>『<a href="'.$item->url.'">'.$item->title.'</a>』<br class="float_clear" /></h4></dd>'; } </dl> </div> <!-- end youtube -->
2008年5月27日
PHPでよく利用するPEARライブラリ「Pager」機能を
WordPressで実装できないかと調べてみたところ
WP-PageNavi 2.30がよさそうなので導入してみました。
まずwp-content/pluginsにダウンロードした「wp-pagenavi」を設置
ページナビゲーションを挿入したいところに(themes/index.phpなど)
<?php wp_pagenavi(); ?>
<?php wp_pagenavi_dropdown(); ?>
2008年5月26日
サイドバーに特定のカテゴリーのみを表示させたいと思い
任意の場所に下記を記述するとカテゴリ中のタイトルと記事を表示できます。
<?php $posts = get_posts('numberposts=2&category=1');
foreach($posts as $post) :
setup_postdata($post); ?>
<h2 class="storytitle"><a href="<?php the_permalink() ?>"
rel="bookmark"><?php the_title(); ?></a></h2>
<div class="storycontent">
<?php the_content(__('(more...)')); ?>
</div>
<php endforeach; ?>を記述しコードの1行目の下記箇所を変更
numberposts=2←表示させたい記事の件数
さらに
category=1←カテゴリの通しID
で表示できます。