私は英語ではないので、言葉の問題でごめんなさい!テンプレートシステムで投稿タグを表示したいのですが、これだけで完璧に機能します:
<?php
$text= "hi,ok,bye";
$numKeys=substr_count($text, ',');
for($i=0;$i<=$numKeys;$i++){
$exp=explode(",",$text);
$tags=$exp[$i];
echo "<a href='http://test.com/$tags'><strong>$tags</strong></a> ";
}
?>
しかし、テンプレートシステムでそれを使用すると機能しません(投稿のタイトル、時間、...投稿タグだけで完璧に機能します!(最初のタグを表示するだけです!:hiのようなタグを1つだけ)):
//posts
$start = strpos($theme, '<start>');
$end = strpos($theme, '</end>', $start + strlen('</end>'));
$posty = substr($theme, $start, $end - $start);
$post = $posty;
$post = str_replace('<start>','',$post);
$post = str_replace('</end>','',$post);
$post_query = mysql_query("SELECT * FROM `posts` WHERE `bid`='{$bid}' ORDER BY `id` DESC");
$posts = '';
if($post_query) {
while($post_data = mysql_fetch_array($post_query)) {
$postid = $post_data['id'];
$post_temp = $post;
$post_temp = str_replace('[post_title]', $post_data['title'], $post_temp);
$post_temp = str_replace('[post_content]', $post_data['content'], $post_temp);
$post_temp = str_replace('[post_date]',$post_data['date'], $post_temp);
$post_temp = str_replace('[post_author]',$post_data['author'],$post_temp);
$post_temp = str_replace('[post_comments]',$post_data['comments'],$post_temp);
$post_temp = str_replace('[post_full_content]','',$post_temp);
$text= "hi,ok,bye";
$numKeys=substr_count($text, ',');
for($i=0;$i<=$numKeys;$i++){
$exp=explode(",",$text);
$tags=$exp[$i];
$post_temp = str_replace('[post_tag]',$tags,$post_temp);
}
$posts .= $post_temp;
}
}
$theme = str_replace($post, $posts, $theme);