Answer the question
In order to leave comments, you need to log in
What's wrong with the regex for h1 tag search?
$text="fhdsklf sdoijf ds <h1>jfidsfj</h1> jklsfdjflks";
$pattern ="!<h1>.+</h1>!";
preg_match($text, $pattern, $matches);
print_r($matches);
Answer the question
In order to leave comments, you need to log in
You need to swap $pattern and $text
Also I advise you to use .+? instead of .+, because otherwise, the regular expression will look for the last occurrence in the string.
$text="fhdsklf sdoijf ds <h1>jfidsfj</h1> jklsfdjflks";
$pattern ="!<h1>.+?</h1>!";
preg_match($pattern, $text, $matches);
print_r($matches);
Regulars and html parsing. Never do that. You have to use special. libraries, for example, here you can choose something. In general, it is better not to use regular games anywhere and never. They say using regular expressions you get two problems from one at once.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question