Jump to content

[SOLVED] Grabbing Info from another page....


PHPNewbie55

Recommended Posts

I am trying to grab some data from another site...

 

I need to grab the data inbetween these tags:

 

<span id="inv_message">CONTENT</span>

 

This is the current inventory of the individual product...

 

The <span id="inv_message"></span> is always the same.. just the content changes.

 

I read this post :: http://www.phpfreaks.com/forums/index.php/topic,172445.0.html

But I couldn't figure out how to just grab the data inbetween the <span id="inv_message">  AND THE </span>

 

Any Advice..??

 

Link to comment
https://forums.phpfreaks.com/topic/82069-solved-grabbing-info-from-another-page/
Share on other sites

I am trying something like this:::

 

 

<?php

$data = file_get_contents("http://www.THE_URL.com");
$inventory = preg_match('/<span id=\"inv_message\">.*?<\/span>/',$data);
print "$inventory";

?>

 

But that isn't right... it just returns 1

 

I am missing something.....

preg_match returns a bool integer for success or failure. You need to pass it the variable that you want it to put the matches found into.

<?php

$data = file_get_contents("http://www.THE_URL.com");
preg_match('/<span id=\"inv_message\">.*?<\/span>/',$data, $matches);
print_r($matches);

?>

 

http://www.php.net/manual/en/function.preg-match.php

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.