I’m using preg_match_all to find a URL in a HTML file. The URL always appears at the start of the line, with no leading space, like this:
<A HREF="/link/to/here"><strong>Next</strong></A>
I used this to match it:
preg_match_all('|^<A HREF="(?<url>.*?)"><strong>Next</strong>|', $html, $url_matches);
It didn’t work until I removed the carat (^) character. I thought that the carat matched the start of a line. Why is it causing my match to fail?
You have to add the
mmodifier:then
^matches at start of a line, else it would only match at the start of the entire string.More Info: http://php.net/manual/en/reference.pcre.pattern.modifiers.php