Jump to content

Get HTML source code


Guest FirefoxRocks
 Share

Recommended Posts

Guest FirefoxRocks

I was wondering how do I get the HTML source code of another page using PHP.It would be best if the code was in a string, but any format will do as I will search through the text to find certain phrases within.One example is the W3C validator, how is it able to "show source" of another page? (even though it isn't written in PHP)Is there some kind of include code or something?

Link to comment
Share on other sites

One way is to use a function like file_get_contents. file_get_contents and fopen will only work across HTTP if the PHP option allow_url_fopen is enabled. If not, then you can use a socket, which is pretty much manually making a connection to the server and getting the page sort of the same way your browser does it. There is also a library called curl that is built to make things like getting URLs easier than using all of the individual socket functions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...