Created
March 11, 2012 08:31
-
-
Save willwade/2015608 to your computer and use it in GitHub Desktop.
Get a list of links from a page
This file contains 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://en.wikipedia.org/wiki/Occupational_therapy"; | |
$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 | |
foreach($matches[2] as $link) | |
{ | |
echo $link."\n"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment