php – 在同一个字符串上多次使用str_replace
发布时间:2020-12-13 14:06:59 所属栏目:PHP教程 来源:网络整理
导读:我从表中循环了一个标题,所以它基本上是这些东西. foreach($c as $row){ echo string_shorten($row['title']);} 我正在做的是尝试是一个switch语句,可以在我想要的搜索之间切换,一旦它被发现用str_replace中我选择的替换: function string_shorten($text){
我从表中循环了一个标题,所以它基本上是这些东西.
foreach($c as $row){ echo string_shorten($row['title']); } 我正在做的是尝试是一个switch语句,可以在我想要的搜索之间切换,一旦它被发现用str_replace中我选择的替换: function string_shorten($text){ switch(strpos($text,$pos) !== false){ case "Hi": return str_replace('Hi','Hello',$text); break; } } 任何建议或可能的替代方案将不胜感激.感觉我真的很亲近,但不完全相同.
你可以在
manual for str_replace() 阅读
以及这个例子 // Provides: You should eat pizza,beer,and ice cream every day $phrase = "You should eat fruits,vegetables,and fiber every day."; $healthy = array("fruits","vegetables","fiber"); $yummy = array("pizza","beer","ice cream"); $newphrase = str_replace($healthy,$yummy,$phrase); 这意味着您可以使用以下内容 $search = array('Hi','Heyo','etc.'); $replace = array('Hello',''); $str = str_replace($search,$replace,$str); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |