Can someone tell me how I can get the source code of a web page?
Newbie to PHP: don't know where to start.
I want a small script that you can call, giving a URL as input.
And then have the code give the whole source code as output on the browser screen.
Thanks.
OM
How do I get the source code of a web page?
Moderator: General Moderators
Re: How do I get the source code of a web page?
Depends what you "source code". If you want to see the php code - you can't.
If you mean like when you right click on the page and choose "view source", then you can use file_get_contents() and pass a link as an argument.
If you mean like when you right click on the page and choose "view source", then you can use file_get_contents() and pass a link as an argument.
Re: How do I get the source code of a web page?
wow: that did the trick! yes: all i wanted was just the source code of the html. thanks.
i've got the following code now:
as an extra... i also needed to leave certain parts out that i didn't want to output.
thats what the second line is about.
i've got the following code now:
Code: Select all
<?php
$rawPageCode = htmlspecialchars(file_get_contents('http://www.domain.com'));
$cleanPageCode = preg_replace("/<!--\s*Admin Code Start\s*-->.*?<!--\s*Admin Code End\s*-->/is", "", $rawPageCode);
echo $cleanPageCode;
?>thats what the second line is about.