str_replaced函数的问题?

WBOY
Release: 2016-06-23 13:26:46
Original
959 people have browsed it

$bodytext = str_replace("%body%", "black", "<body text='%body%'>");var_dump($bodytext);echo str_replace("world","John","Hello world!");
Copy after login

输出

为什么var_dump($bodytext)会输出string(19) "";是那里错了?设置还是语法?


回复讨论(解决方案)

$bodytext = str_replace("%body%", "black", "<body text='%body%'>");var_dump($bodytext);
Copy after login
string(19) "

"

你只看到 string(19) ""  的原因是:你用浏览器查看时, 被当做 html 标记解释了,所以看不见

谢谢

应该要用字符实体表示,输出的值为空,是浏览器把它当成一个html标签了:
 $bodytext = str_replace("%body%", "black", "");
          var_dump($bodytext);
         echo str_replace("world","John","Hello world!");
不知道您是不是指的这个?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template