如何从PHP中的丰富字符串末尾删除数字?

时间:2015-03-11 19:38:09

标签: php string replace

我的字符串格式如下:

$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;

但我怎么能为所有格式做到这一点?

1 个答案:

答案 0 :(得分:0)

将正则表达式从/\d+$/更改为/[\s+\d+]{1,}$/