当前位置: 代码迷 >> PHP >> 一个很奇怪的PHP有关问题
  详细解决方案

一个很奇怪的PHP有关问题

热度:157   发布时间:2016-04-28 20:42:02.0
一个很奇怪的PHP问题
我要把$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

------解决方案--------------------
var_dump($one_news['content']); 
$news[content]=str_replace('"','\'',$one_news['content']);
var_dump($news[content]);

分别输出什么
------解决方案--------------------
引用:
我要把$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']);


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