youngnickodemus Posted February 19, 2009 Share Posted February 19, 2009 Hi all, I'm really having issue with something that i think should be very basic, but it's really starting to get on my nerves...if anyone can help i'd really appreciate it! Basically i've written a price scraping script which works fine for most things, but i'm struggling to write the regex for one particular price i'm trying to scrape from a site. The html i'm searching through is: <span class="lprice"> £312.34 </span> I want to extract the price '312.34', but i can't get any joy at all. The php i'm using is basically: $expression = "<span class=\"lprice\">\n£(.*?)\n<\/span>"; preg_match($webpage, $expression, $result); I'd really appreciate any advice! THanks, Nick Quote Link to comment Share on other sites More sharing options...
youngnickodemus Posted February 20, 2009 Author Share Posted February 20, 2009 I really need help on this guys...quite urgently.... Does anyone know how i'm supposed to format the regex for this??? Cheers, Nick Quote Link to comment Share on other sites More sharing options...
Mad Mick Posted February 20, 2009 Share Posted February 20, 2009 You missed the space/tabs between the span open tag newline and the £ Quote Link to comment Share on other sites More sharing options...
youngnickodemus Posted February 20, 2009 Author Share Posted February 20, 2009 You missed the space/tabs between the span open tag newline and the £ Thanks Mike. I just tried: <span class=\"lprice\">\n(.*?)£(.*?)\n<\/span> and that didn't work either....? any ideas?? Cheers, Nick Quote Link to comment Share on other sites More sharing options...
Mad Mick Posted February 20, 2009 Share Posted February 20, 2009 Tried that here, and seems OK: http://erik.eae.net/playground/regexp/regexp.html I'm no regex expert though - use it v rarely so can't help much more... Quote Link to comment Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 <?php $string = '<span class="lprice"> £312.34 </span>'; preg_match("~<span.+?;(.+?)</span>~is", $string, $matches); $price = $matches[1]; echo $price; die(); ?> Should do what you want. As a note if you have multiple spans with a ; inside of them you may want to add the class= part. If you do not then this should be fine, especially if it is the first span, as this will only match the first item on the page that matches that regex. 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.