How to change the source code and modify/parse a website?

Earlier I had written an article on How to get(view) html source code of a website . I had created an application and that would grab the html code of any website. In this article, I will be writing on how you can modify the looks of a website by changing the html source code after you grab it.

At first the html source code getting part. I have commented in the code for better understanding.


$domain = $_POST['domain'];
$handle = fopen("http://$domain","r");
$contents = '';

while (!feof($handle)) {
    $contents .= fread($handle, 8192);
}
//var_dump($contents);

fclose($handle);

Now, the modification in the source code part. I have used ereg_replace() function for the modification.


$code = $_POST['code'];
$present = $_POST['present'];
$replace = $_POST['replace'];

$code = ereg_replace($present, $replace , $code);
echo stripslashes($code);
exit;

Download

Thanks.