Click to See Complete Forum and Search --> : Fetching html page code from the web address!


sunny747
08-25-2006, 03:26 PM
HI,
suppose my site address is www.something.com/details.php?id=4
I would like to fetch the (view->source) source code of html only and put it in the database. Inserting in db may not be a problem but how to fetch the code from the web address?
I want only the html code with info not the php codes.

To make things easier, how to display html code of www.something.com/details.php?id=4 in textarea?

is it possible? any idea?

thanks so much

PineSolPirate
08-25-2006, 04:17 PM
Here's some JS to get everything inside the "html" tags.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<textarea id='taf' rows="15" cols="60"></textarea>
</body>
</html>
<script type="text/javascript">
window.onload = function () {
document.getElementById('taf').value = document.getElementsByTagName("html").item(0).innerHTML;
}
</script>

Otherwise you can use cURL to fetch pages:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.google.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
// Return to string not browser
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Get it
$curlData = curl_exec($ch);
curl_close($ch);

// All your source is in $curlData
print "<textarea>$curlData</textarea>";
?>

NogDog
08-25-2006, 05:02 PM
$html = file_get_contents("http://www.something.com/details.php?id=4");

(Even if it's on the local host, use the full "http[s]://..." URI.)

sunny747
08-26-2006, 01:38 AM
Thank you soo much guys...it is working like a charm.....!!:)