Sunday , October 21 2018
Home / PHP / GET THE SOURCE CODE OF A WEBPAGE

GET THE SOURCE CODE OF A WEBPAGE

Using the function below you would be able to get the HTML code of any webpage.

function display_sourcecode($url)
{
$lines = file($url);
$output = “”;
foreach ($lines as $line_num => $line) {
// loop thru each line and prepend line numbers
$output.= “Line #<b>{$line_num}</b> : ” . htmlspecialchars($line) . “<br>\n”;
}
}

Syntax:

<?php
$url = “http://w2class.com”;
$source = display_sourcecode($url);
echo $source;
?>

About admin

Check Also

Resize Images in php

Creating thumbnails of the images is required many a times, this code will be useful ...

Leave a Reply