帮我php str_replace函数替换

我想读取文本中遇到数据库里面的标题字段的某个标题的时候把它替换超链接。
我的代码如下:
mysql_query('use kitab',$conn);
mysql_query('set names utf8',$conn);
// 改变标签链接
$rep=mysql_query('select * from arhip WHERE a_name<>""',$conn);

while ( $rs_rep=mysql_fetch_assoc($rep)) {
$mawzu[]=$rs_rep['a_name'];
$rep_id[]=$rs_rep['a_id'];
}
///----- 就读文本
$sql='select * from arhip where a_id='.$_GET['id'];
$row=mysql_query($sql,$conn);
$rs=mysql_fetch_assoc($row);

$url = '?id='.$rep_id;
//更改标签
$mazmun=str_replace($mawzu,'<a href="'.$url.'">'.$mawzu.'</a>',$rs['a_quxandurux']);

//读取
//标题
echo '<p class=Title>'.$rs['a_name'].'</p>';
//头部
echo '<div class="top-info">';
//添加用户
echo "<p>ئۇچۇر قوشقۇچى: <a href=../user.php?class=".$rs['a_adduser'].">".$rs['a_adduser']."</a></p>";
//打开一次加一读数
echo 'ئۇقۇش قېتىم سانى : '.$a_read=$rs['a_read']+1;
//更新时间
echo "<p>يېڭىلانغان ۋاقتى: <a>".$rs['a_updatetime']."</a></p>";
//头部完毕
echo '</div>';
//段落,文本
echo '<p class=Mezmun>'.$mazmun.'</p>';
// 底部
echo "<div class='read-bottom'>";
//标题类型
echo "<p>تۈر: <a href=../class.php?class=".$rs['small_tur'].">".$rs['small_tur']."</a></p>";
//添加时间
echo "<p>قۇشۇلغان ۋاقتى: <a>".$rs['a_createdate']."</a></p>";

//底部完毕
echo "<div>";

//添加读数
$update="UPDATE arhip set a_read=".$a_read." WHERE a_id=".$_GET['id'];
mysql_query($update,$conn);

?>

写了这样把替换的字符全部显示为 Array

第1个回答  2015-01-28
  while ( $rs_rep=mysql_fetch_assoc($rep)) {

        $mawzu[]=$rs_rep['a_name'];

        $rep_id[]=$rs_rep['a_id'];

    }

 改成

  while ( $rs_rep=mysql_fetch_assoc($rep)) {
     $mawzu[ $rs_rep['a_id'] ]=$rs_rep['a_name'];
  }

 $mazmun=str_replace($mawzu,'<a href="'.$url.'">'.$mawzu.'</a>',$rs['a_quxandurux']);

改成

foreach( $mawzu as $key => $val ) {
    $mazmun=str_replace( $val, "<a href=\"?id={$key}\">{$val}</a>", $rs['a_quxandurux']);
}

追问

这样也是一样的。还是替换等于最后一条的标题。