Home » PHP2 July 2008

PHP: How to get (view) html source code of a website

Here is the PHP code to fetch the html source code of any website specified. fopen function is used to open the website URL. stream_get_contents is used to read the opened URL. The fetched code is displayed inside a textarea.

Hope it helps.


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Thanks a lot for tons for support mukesh…

    BTW….if you’re using PHP 4.3 or more you can use


    to do this in a easy way but fopen_wrappers must be enabled in PHP setting to get the content from URL using this function and in most of the server they are enabled by default..

  • Mackenzie

    hey we got the interface, but when we typed in the URL in the box it didnt work. please assist us.

  • I think that, you wrote the url as “http://www.chapagain.com.np” . Don’t put “http://” in front. Just write “www.chapagain.com.np” (without quote) or you can simply write “chapagain.com.np”. (I have given my website url as example. You can use your own.)

  • I wonder if you can get generated content? I use a lot of JS all the time on my sites and if I could get generated content that would be cool, unfortunately I know this would be impossible since it would have to run the actual JS. Dang!