phoenixx Posted April 22, 2010 Share Posted April 22, 2010 Just wondering if anyone knows which method I should use for the following issue: I'm scraping a page (in this case a craigslist ad) and trying to get the content between these two tags: <div id="userbody"> and <!-- START CLTAGS --> . I'm using a regex that isn't returning anything, but would it be cleaner just to explode or strpos the string? Here's the code I'm using: $data = @file_get_contents('http://houston.craigslist.org/fud/1704346680.html'); preg_match('/class="userbody">([^"]*)<!-- START CLTAGS -->/is',$data,$resultscontent); echo $resultscontent[1]; Thanks in advance for your help. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted April 22, 2010 Share Posted April 22, 2010 The regex isn't working because you are using class=" instead of id=" since it's the div id you are trying to match Quote Link to comment Share on other sites More sharing options...
phoenixx Posted April 22, 2010 Author Share Posted April 22, 2010 A typo - the data is id="userbody" but even changing that doesn't work. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted April 22, 2010 Share Posted April 22, 2010 $data = file_get_contents('http://houston.craigslist.org/fud/1704346680.html'); preg_match('/id="userbody">(.*?)<!-- START CLTAGS -->/is',$data,$resultscontent); echo $resultscontent[1]; Quote Link to comment Share on other sites More sharing options...
phoenixx Posted April 22, 2010 Author Share Posted April 22, 2010 PERFECT!!!! Many Thanks! Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted April 22, 2010 Share Posted April 22, 2010 No problem 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.