Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I'm trying to extract all links from an external website.Code: Select all
<?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);
$urlpattern = '/<a .+<\/a>/i';
preg_match_all($urlpattern, $html, $matches);
printf("Output of URLs %d URLs<P>", sizeof($matches[0]));
foreach ($matches[0] as $u) {
$u = trim($u);
echo $u."<br>\n";
}
}
?>Using the code
Code: Select all
<?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);
echo $html;
}
?>e.g. http://www.weberdev.com/ has lots of links, but only the header is returned using the code given above.
Is there a way I can get the source code of an external website as if it was being opened in a browser?
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]