在两行之间替换文本 [英] Replacing text between two limts
本文介绍了在两行之间替换文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试将两个符号之间的文本替换为preg_replace
,但是可惜仍然无法完全正确,因为我得到的是空字符串,这是到目前为止的结果>
I have been trying to get the text between two symbols to be replaced with preg_replace
, but alas still not quite getting it right as I get a null output that is empty string, this is what I have so far
$start = '["';
$end = '"]';
$msg = preg_replace('#('.$start.')(.*)('.$end.')#si', '$1 test $3', $row['body']);
所以我要寻找的示例输出将是:
So an example output I am looking for would be:
normal text [everythingheregone] after text
收件人
normal text [test] after text
推荐答案
您正在将$ start和$ end定义为数组,但将其用作普通变量.尝试将代码更改为此:
You are defining $start and $end as arrays, but using it as normal variables. Try changing your code to this:
$start = '\[';
$end = '\]';
$msg = preg_replace('#('.$start.')(.*)('.$end.')#si', '$1 test $3', $row['body']);
这篇关于在两行之间替换文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文