Sunday, January 1, 2012

View html source code using php

2 comments
ooking for php script that can view external html page source?
well you came into the right place, i wrote 2 different php scripts which can be used to view html source code

here's the code


CURL



<?php
 $url='http://example.com'; // target url
 $ch=curl_init();
 curl_setopt($ch,CURLOPT_URL,$url);
 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
 $htmlcode=curl_exec($ch);
 curl_close($ch);

 // output the html code
 echo nl2br(htmlentities($htmlcode));
?>


___________________________________________________

FILE_GET_CONTENTS




<?php
 $url='http://example.com'; // target url
 $htmlcode=file_get_contents($url);
 
 // output the html code
 echo nl2br(htmlentities($htmlcode));
?>


______________________________________________

 you can do it also by php dom, fopen etc..
so you noticed i used nl2br? yes but that is not necessary. i used this function (nl2br) to convert the "\n" to <br />

okay hope this small code helped you:)

2 comments:

  1. I have no words for this great post such a awe-some information i got gathered. Thanks to Author.
    html5 converter

    ReplyDelete
  2. I am hosting my website Free on QuotesFox.com
    Its providing
    10 GB space
    100 GB monthly bandwidth
    Free Sub Domain
    Unmetered MySQL space
    PHP + MySQL
    Cpanel full featured
    PhpMyAdmin
    Firewall Protection
    UPS Power Back-up/Back-up
    Hotlink Protection
    Forum support [ http://quotesfox.com/forums ]
    and most importantly no ads
    My website is working like a charm with a lot of monthly traffic.
    This is worth taking look.
    QuotesFox.com

    ReplyDelete