带有通配符的preg_replace语法

问题描述 投票:0回答:1

尝试了几个小时。它是简单的文本(字符串)。有人可以告诉我这种语法有什么问题吗?无法运作

$finalcontent = preg_replace('/<h2>.*?<\/div><\/div>/', '</h2>$variable</div></div>', $finalcontent);

提前感谢。

php syntax preg-replace
1个回答
0
投票

您不能在单引号中添加变量,第二个参数应在双引号中“ $ variable”,而不是'$ variable'

您可以在此处找到单引号和双引号的很好参考:What is the difference between single-quoted and double-quoted strings in PHP?

© www.soinside.com 2019 - 2024. All rights reserved.