Home > Article > Backend Development > Find PHP code for all links in a page
In this example, we want to use file_get_contents to get the content of a web page. Then use str_replace("n", "", $html) to remove all line breaks. Then use preg_replace('//', "n", $html) to put all .... patterns on a new line. Finally, use preg_match_all('/.*?/', $html, $matches) to match the link pattern. /.*?/ is a regular expression that matches this pattern. So why do we put the ..... link on a new line? ? Because in the /.*?/ pattern, .* cannot match newlines, so if and are not on the same line, they cannot match! ! So we're going to do this! |