使用 preg_replace 将文本添加到行中


Using preg_replace to add text into line?

这是我正在使用的示例行:

<br/>
About Company Name<br/>
<p>This is just some random text About nothing.</p>
<br/>

基本上我想操纵任何以 About 开头并以 <br/> 结尾的行。

我只想这样加粗:<b>About Company Name</b><br/>

我可以找到这样的文本:

^About.*<br/>

但是我不知道如何添加粗体符号。 任何帮助将不胜感激。

捕获组添加到正则表达式中,如下所示:

^(About.*)<br'/>$

然后像这样使用正则表达式:

$s = preg_replace('/^(About.*)<br'/>$/m', '<b>$1</b><br/>', $s);

正则表达式 101 已测试