2013-04-06 31 views
-1

我应该说我不是英语,所以对于单词问题感到抱歉! 我想显示的标签后在我的模板系统,这个单独工作完美:如何在我的模板系统中显示帖子标签

 <?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> "; 
    } 
?> 

,但是当我在我的模板系统使用它,它不工作(文章标题,时间,工作...完美的只是后标签不工作(只显示第一个标签只是一个标签,如:嗨!)):

 //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); 
+0

你是什么意思'不工作?它会给你一个错误?它显示不正确吗? – 2013-04-06 21:13:06

+0

我的意思是它只显示第一个标签!只有一个标签:嗨 – user1968224 2013-04-07 10:50:35

回答

0

str_replace

str_replace函数 - 更换所有个事件与替换字符串

这意味着搜索字符串的所有[post_tag] s将被第一$tags值代替。以下每个$tags都不起作用。

相关问题