Hi! Google I did! Found this super piece of code :-) I notice that it does however fail to pick up relative URLs, and was hoping that I could quickly edit $urls = '(http|file|ftp)'; to read $urls = '(http|file|ftp|(../){1,})'; Yes! Indeed it is laughable, cos I don't understand the preg_match below I imagine. Could anybody talk their way through the preg_match below. Have been to:
http://www.phpbuilder.com/columns/dario19990616.php3 where there is a good little tutorial I found on regex stuff, but I don't understand this bit:
(?=
[$punc] *
[$any]
|
$
)
Can anyone enlighten me or tell me where I can RTFM 🙂
Malc
ENTIRE CODE SNIPPIT:
<?php
if (getenv('REQUEST_METHOD') == 'POST') {
$url = $POST[url];
} else {
$url = $GET[url];
}
?>
<form action="<?= $PHP_SELF ?>" method="POST">
URL:<input type="text" name="url" value="<?= $url ?>"/><br>
<input type="submit">
</form>
<?php
if ($url) {
$remote = fopen($url, 'r');
$html = fread($remote, 1048576);
fclose($remote);
$urls = '(http|file|ftp)';
$ltrs = '\w';
$gunk = '/#~:.?+=&%@!\-';
$punc = '.:?\-';
$any = "$ltrs$gunk$punc";
preg_match_all("{
\b
$urls :
[$any] +?
(?=
[$punc] *
[^$any]
|
$
)
}x", $html, $matches);
printf("Output of URLs %d URLs<P>\n", sizeof($matches[0]));
foreach ($matches[0] as $u) {
$link = $PHP_SELF . '?url=' . urlencode($u);
echo "<A HREF='$link'>$u</A><BR>\n";
}
}
?>