Unknown modifier while using preg_quote() in preg_match_all()

I am having a problem with my preg_match_all() function. I have a string e.g.

$string = '<div id="header">Hello</div>'
preg_match_all('/'.preg_quote('<div id="header">').'(.*?)'.preg_quote('</end>').'/s', $string, $matches);

And I am looking to get the output Hello.

But I only get this error:

preg_match_all(): Unknown modifier 'd' in C:\xampp\htdocs\classes\Functions.php on line 13

Upvotes: 0

Views: 464

Answers (1)

Rizier123
Rizier123

Reputation: 59701

You have to specify the delimiter for preg_quote(), so just add the delimiter as a second argument, like this:

preg_match_all('/' . preg_quote('<div id="header">' , "/") . '(.*?)' . preg_quote('</end>', "/") . '/s', $string, $matches);
                                                    //^^^                                   ^^^

Upvotes: 6

Related Questions