PHPNewbie55 Posted December 17, 2007 Share Posted December 17, 2007 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..?? Quote Link to comment Share on other sites More sharing options...
PHPNewbie55 Posted December 17, 2007 Author Share Posted December 17, 2007 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..... Quote Link to comment Share on other sites More sharing options...
lemmin Posted December 17, 2007 Share Posted December 17, 2007 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 Quote Link to comment Share on other sites More sharing options...
PHPNewbie55 Posted December 17, 2007 Author Share Posted December 17, 2007 Cool... that prints: <?php Array ( [0] => Quantity on Hand: 5 ) ?> So how do I get it to just print: Quantity on Hand: 5 Totally dumb noob here.............. ??? Quote Link to comment Share on other sites More sharing options...
lemmin Posted December 17, 2007 Share Posted December 17, 2007 If there is only one match, you can just use the first index of the array, 0, and print it. If there are more, you can loop through the array and print each one. echo $matches[0]; Quote Link to comment Share on other sites More sharing options...
PHPNewbie55 Posted December 17, 2007 Author Share Posted December 17, 2007 I got it... <?php print "$matches[0]"; ?> That really helps a lot thank you very much!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.