我要把$one_news里面的content字段的双引号替换为单引号,然后赋给$news[content],但是发生了很奇怪的问题,如下:

//这样可以
$one_news['content']=str_replace('"','\'',$one_news['content']);
$news[content]=$one_news['content'];
//下面的这样子就替换不掉双引号,为什么呢?
//$news[content]=str_replace('"','\'',$one_news['content']);PHP

解决方案 »

  1.   

    var_dump($one_news['content']); 
    $news[content]=str_replace('"','\'',$one_news['content']);
    var_dump($news[content]);分别输出什么
      

  2.   


    你上面的那个替换是覆盖了原来的值,而下面那个替换$one_news['content']值仍然保持不变,结果存到了$news[content]里,替换都没问题。你说没替换成功肯定是你看到后面那个的$one_news['content']值没有改变。