PHP str_replace()字符串匹配

发布网友 发布时间:2022-04-06 01:08

我来回答

3个回答

热心网友 时间:2022-04-06 02:37

如果数字不确定,可以用正则替换

$str = "(123,123,123,";
$str = preg_replace('/(\d+),(\d+),(\d+),/', '${1},${2},${3})', $str);

echo $str;

或者

$str = "(123,123,123,";
$str = preg_replace('/\(([\d,]+),/', '(${1})', $str);

echo $str;

热心网友 时间:2022-04-06 03:55

$string = "(123,123,123,";
$pattern = "/(\d+\,\d+\,\d+),/";
$replacement = "$1)";
$string = preg_replace($pattern, $replacement, $string);

热心网友 时间:2022-04-06 05:30

如果数字不确定,可以用正则替换
$str
=
"(123,123,123,";
$str
=
preg_replace('/(\d+),(\d+),(\d+),/',
'${1},${2},${3})',
$str);
echo
$str;
或者
$str
=
"(123,123,123,";
$str
=
preg_replace('/\(([\d,]+),/',
'(${1})',
$str);
echo
$str;

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com