【发布时间】:2015-09-06 08:35:53
【问题描述】:
我有两个字符串,如下所示:
$str1='this is the first text';
$str2='this is the second text';
现在我用str_replace();代替str1和str2中的'first'这个词。
对于str1:主题将被找到,然后将被替换
str_replace('first','matched',$str1);
// output: this is the matched text
对于str2:找不到主题,str2 不会改变。
str_replace('first','matched',$str2);
// output: this is the second text
现在我想echo:
'匹配已找到' for
str1str2'找不到匹配的'。
而且我还想知道是否可以计算找到的匹配数量?例如对于str1 是1。
【问题讨论】:
标签: php str-replace string-matching