我一直在尝试使用preg_replace
替换两个符号之间的文本,但是仍然没有完全做对,因为我得到了一个空字符串的null输出。以下是我目前的代码:
$start = '["';
$end = '"]';
$msg = preg_replace('#('.$start.')(.*)('.$end.')#si', '$1 test $3', $row['body']);
所以我需要的例子输出如下:
normal text [everythingheregone] after text
To
normal text [test] after text
$start
和$end
锚点必须是字符串,并且必须进行转义。您正在使用数组,而[
会成为一个问题。 - mario