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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.