Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to print HTML code of any website using PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 244
    Comment on it

    Hello Reader's if you want to get all of the HTML code of any website then you use the function as below:-

    The first way is by using PHP in built function url fopen, and its code will go like this:-

    $ShowHTML = file_get_contents('http://findnered.com/blogs/');
    

    echo $ShowHTML;

    This is the most simple and easy way. Now if you need more control then other way is cURL. It's code will go like this:-

    $GetHTML = curl_init('http://findnered.com/blogs/');
    curl_setopt($GetHTML , CURLOPT_RETURNTRANSFER, true);
    $ShowHTML= curl_exec($GetHTML );
    if (curl_error($GetHTML ))
        die(curl_error($GetHTML));
    // Here you can also get the status of page
    $ProcessStatus= curl_getinfo($GetHTML , CURLINFO_HTTP_CODE);
    curl_close($GetHTML );
    

    So choosing cURL is also a good option if you want other details of the webpage like Status of page.
    Both of the way will work fine on php version >5 you just have to configure cURL before using second way.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: