假设我有一个字符串
$string = 'this is my gal_s, not my 1_s not 2_s not 3_s';
$find = '_s';
$replace = '';
我想回来
"this is my gal_s, not my 1 not 2 not 3"
所以这个词gal_s
不受影响
这可能吗?
假设我有一个字符串
$string = 'this is my gal_s, not my 1_s not 2_s not 3_s';
$find = '_s';
$replace = '';
我想回来
"this is my gal_s, not my 1 not 2 not 3"
所以这个词gal_s
不受影响
这可能吗?
您可以像这样使用 preg_replace 和否定的lookbehind:
$repl = preg_replace('/(?<!\bgal)_s/', '', $str);
@anubhva answar 也不错,也可以替代尝试
$string = 'this is my gal_s, not my 1_s not 2_s not 3_s';
$find = '_s';
$replace = '';
$arr = explode(',', $string);
$arr[1] = str_replace('_s', '', $arr[1]);
echo $string = implode($arr);