我从表中循环了一个标题,所以它基本上是这些东西.
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; } }
任何建议或可能的替代方案将不胜感激.感觉我真的很亲近,但不完全相同.
你可以在
@L_502_0@阅读
原文链接:https://www.f2er.com/php/131097.htmlmixed
str_replace
( mixed$search
,mixed$replace
,mixed$subject
[,int&$count
] )
以及这个例子
// 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);