<html><head><title>Link Extractor</title>
<?
$url = $_REQUEST[url];
if ( $url == "Hidden" )
{ die("Enter a valid URL"); }
if ( $url == "http://")
{ die("Enter a valid URL"); }
# fix relative links
if ( isset($url))
{ echo "<base href=\"$url\">"; }
?>
</head>
<body bgcolor="#fad888" text="black">
<form action="http://eclecticdjs.com/mike/tutorials/php/examples/link_extractor.php">
<center>
<input type="text" name="url" size="25" autoactivate value="<?
if ( isset($url) )
{ echo "$url"; }
?>">
<input type="submit" value="Extract Links">
</center>
</form>
<br><br>
<?
if ( isset($url) )
{
# assign source code to string variable
$file = file_get_contents("$url");
# find all links, assign to $links_list
preg_match_all( "@<a[^>]*>[^>]*(/a>)@i", $file, $links_list);
# output links
foreach( $links_list[0] as $index=>$var)
{ echo "$var<br />\n"; }
}
?>
</body>
</html>