Tag Archives: h1

PHP regular matching H1 datagram error preg_ match(): Unknown modifier ‘h’ in

Question:

$str = "<h1>this is test msg</h1>";
$ruler = "/^<h1>(.*?)</h1>$/";
$res = preg_match($ruler,$str,$v);
var_dump($v);

Error:
Warning: preg_match(): Unknown modifier 'h' in /usr/local/var/www/test.php on line 36
NULL

Why is it wrong?The reason is because of my delimiter

in regular rules, the/do delimiter is used, while in </ h1> There are also /, so such errors will be reported

Solution:

1. Will < h1> I’d like to change it to </ h1> It’s OK

$ruler = "/^<h1>(.*?)<\/h1>$/";

2. Change the delimiter