Created
May 16, 2013 11:36
-
-
Save ghalusa/5591124 to your computer and use it in GitHub Desktop.
Parsing anchors in rendered html with php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = "http://www.imdb.com/movies-in-theaters/"; | |
$input = @file_get_contents($url) or die("Could not access file: $url"); | |
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"; | |
if(preg_match_all("/$regexp/siU", $input, $matches)) { | |
// $matches[2] = array of link addresses | |
// $matches[3] = array of link text - including HTML code | |
echo "<pre>"; | |
var_dump($matches[2]); | |
echo "</pre>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment