Jump to content

Grab info from external web site


christa

Recommended Posts

You could use a function like file_get_contents() to put all the HTML into a string, such as:

 

<?php 
$html = file_get_contents("http://www.phpfreaks.com");
?>

 

You can then split every line into an array by using explode() and loop through them looking for specific text:

 

<?php 
$html = explode("\n", file_get_contents("http://www.phpfreaks.com"));

foreach ($html as $data) {
	if (preg_match("/TEXT HERE/", $data))
		echo $data;
}
?>

 

The pattern you use depends on the website you're grabbing data from. If you post the website you need to get text from and the exact text you need to grab I'll have a look.

Well, the following code works but the problem is, the text on the original site updates constantly using Ajax, so when the page is first loaded most of the text isn't there and the text that is there hasn't been updated to the correct information yet... I'm not sure how to grab text from another website that updates with Ajax to be honest.

 

<?php 
$html = explode("\n", file_get_contents("http://www.n2yo.com/?s=24905"));
$lines = array("Latitude:", "Longitude:");

foreach ($html as $data) {
	foreach ($lines as $string) {
		if (preg_match("\"" . $string . "\"", $data))
			echo str_replace(
				"	<td><font size=2>", 
				"", 
				str_replace(
					"</td><td><font size=2><B>", 
					"", 
					str_replace(
						"</B></td>", 
						"", 
						$data
					)
				)
			) . "<br />";
	}
}
?>

 

If you can find another source I can possibly help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.