我在网上到处寻找一些有用的信息,我想我发现的太多了。我在试着理解正则表达式,但不明白。比如说$data="A bunch of text [link=123] another bunch of text.",它应该被"< a href=\"123.html\">123< /a>"替换。我试了很多类似的代码:但输出始终与原始$data相同。我想我必须看到一些与我的问题相关的东西,了解基本知识。 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 移除[]周围的多余(),并在+之后添加[0-9]以量化它。另外,请转义组成标记本身的[]。$find = "/\[link=(\d+)\]/"; // "\d" is equivalent to "[0-9]"$replace = "<a href=\"$1.html\">$1</a>";echo preg_replace($find,$replace,$data); (adsbygoogle = window.adsbygoogle || []).push({});