0 php preg-match-all preg-match
我的preg_match_all()功能有问题。我有一个字符串,例如
$string = '<div id="header">Hello</div>'
preg_match_all('/'.preg_quote('<div id="header">').'(.*?)'.preg_quote('</end>').'/s', $string, $matches);
Run Code Online (Sandbox Code Playgroud)
我正在寻找输出Hello。
但我只收到这个错误:
preg_match_all():第 13 行 C:\xampp\htdocs\classes\Functions.php 中的未知修饰符 'd'
您必须为 指定分隔符preg_quote(),因此只需将分隔符添加为第二个参数,如下所示:
preg_match_all('/' . preg_quote('<div id="header">' , "/") . '(.*?)' . preg_quote('</end>', "/") . '/s', $string, $matches);
//^^^ ^^^
Run Code Online (Sandbox Code Playgroud)