[英]php preg_match closing </b>
I have this regex: 我有这个正则表达式:
if(preg_match('/<div class="item"><b>(.+)</b><br>/', $html, $habbo)) {
But I get this error: 但我得到这个错误:
Warning: preg_match(): Unknown modifier 'b' in C:\xampp\htdocs\Jvdw\activeer.php on line 6
Because </b>
close the regex. 因为</b>
关闭了正则表达式。
How to fix this? 如何解决这个问题?
You are using / as a delimiter. 您正在使用/作为分隔符。 I recommend using another character for that: 我建议使用另一个角色:
preg_match('~<div class="item"><b>(.+)</b><br>~', $html, $habbo)
http://www.php.net/manual/en/regexp.reference.delimiters.php http://www.php.net/manual/en/regexp.reference.delimiters.php
What the regex interprets is this: '/<div class="item"><b>(.+)</b'
, because the / is used to stop and start the regex. 正则表达式解释的是: '/<div class="item"><b>(.+)</b'
,因为/用于停止和启动正则表达式。 In this case it tries to us the b as a modifier which doesn't exist. 在这种情况下,它会尝试将b作为不存在的修饰符。
RegEx engine thinks that, RegEx is over at </
in </b>
. RegEx引擎认为,RegEx在</
in </b>
。 You can escape it, with a \\
like this 您可以逃避它,用\\
这样的
<\/b>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.