Heim  >  Artikel  >  Backend-Entwicklung  >  php函数str_replace的使用方法总结_PHP教程

php函数str_replace的使用方法总结_PHP教程

WBOY
WBOYOriginal
2016-07-21 14:54:561000Durchsuche

字符串取代。
语法: string str_replace(string needle, string str, string haystack);
返回值: 字符串
函数种类: 资料处理
内容说明

本函数将字符串 str 代入 haystack 字符串中,将所有的 needle 置换成 str。mlevine@adtraq.com (11-Apr-1999) 指出在 PHP 3.0.7 版,本函数有些 bug,而 nadeem@bleh.org (05-Jun-1999) 补充在 PHP 3.0.8 版本函数就回复正常了。
使用范例

下例将 %body% 以 black 取代

$bodytag = str_replace("%body%", "black", "

");
echo $bodytag;
>

格式:
[@str_replace("要替换的旧内容", "要取代原内容的新字符", $被替换内容的变量名)]
[@str_replace(array('旧1','旧2','旧3'), array('新1','新2','新3'), $被替换内容的变量名)]
[@str_replace(array('旧1','旧2','旧3'), '新内容', $被替换内容的变量名)]
实例:
多对一替换:想把内容字段里所有的

标签清除掉,替换成空

[@str_replace(array('

','

'), '', $Content)]
一对一替换:想把内容字段里所有的
标签换成



[@str_replace('
', '

', $Content)]
多对多替换:想把内容字段里的
换成
, 同时


,把全清除

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/364526.htmlTechArticle字符串取代。 语法: string str_replace(string needle, string str, string haystack); 返回值: 字符串 函数种类: 资料处理 内容说明 本函数将字符串 str 代入...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn