我的字符串格式如下:
$number == 1212 || $number == 12 12 || $number == 1 212 || ...
$string="this is an example $number";
$string="<p>this is an example <b>$number<p>";
$string="<p>this is an example $number<p>";
我将此代码用于干净的字符串,如下所示:
$string="this is an example 1212";
$newString = preg_replace("/\d+$/","",$String );
echo $newString;
但我怎么能为所有格式做到这一点?
答案 0 :(得分:0)
将正则表达式从/\d+$/
更改为/[\s+\d+]{1,}$/