Zaf*_*fee 2 php string str-replace
我有一个字符串
显示324结果中的1 - 12
我想要这个字符串
324结果
要么
324
只要
注意,324是每次获得字符串时都会改变的数字.它可能是2位数(34),3或4位数.
目前我只是在使用代码丢弃显示单词时取得成功
'str_replace('Showing', '', $s)'
Run Code Online (Sandbox Code Playgroud)
这给出了
第1 - 12条,共324条搜索结果
我怎样才能使用str_replace函数来实现我的目的?或者我应该使用PHP的任何其他功能?
你可以用preg_match().
preg_match('/(?P<results>\d+)\sResults$/', $str, $matches);
Run Code Online (Sandbox Code Playgroud)
然后检查$matches['results']结果的数量或结果$matches[0]的数量和' Results'子字符串.