redarrow Posted April 12, 2009 Share Posted April 12, 2009 advance thank you if i wanted to get info from a web site from <p> to </p> how please. my poor example. <?php $url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm"); $result=preg_match_all("#(<p>)(.?)(</p>)#",$url,$match); print_r($match[0][1]); ?> Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Could try this? $page = file_get....... preg_match('/\<p\>(.*?)\<\/p\>/i', $page, $matches); foreach($matches ......... Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 12, 2009 Author Share Posted April 12, 2009 does not work i get array() array() <<<<<<<< got it going yee haaaaaaaa <?php $url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm"); $result=preg_match_all('/\<p\>(.*?)\<\/p\>/i',$url,$match); foreach($match as $m){ echo $m; } ?> Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Idn't that what I put ??? Lol Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 12, 2009 Author Share Posted April 12, 2009 This one wrong why please need alteration lol. no results. <?php $url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm"); $result=preg_match('/\<div class\=\"mvb\"\>(.*?)\<\/p\>/i',$url,$match); foreach($match as $m){ echo $m; } ?> Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 You're currently searching for something like <div class="mvb">(ANYTHING)</p> Is that really what you want to search for? Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 12, 2009 Author Share Posted April 12, 2009 no see the web site in question trying to get all the football results tried this. no joy. <?php $url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm"); $result=preg_match('/\<div class\=\"pvtb\"\>\<b\>Barclays Premier League\<\/b\>\<\/div\>(.*?)\<\/p\>/i',$url,$match); foreach($match as $m){ echo $m; } ?> Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 I just tried this and it worked: <?php $url = '<div class="pvtb"><b>Barclays Premier League</b></div>hello</p>'; //$url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm"); preg_match('/\<div class\=\"pvtb\"\>\<b\>Barclays Premier League\<\/b\>\<\/div\>(.*?)\<\/p\>/i',$url, $matches); foreach($matches as $key => $value) { echo $value; } ?> So it must not be on the page. Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 12, 2009 Author Share Posted April 12, 2009 get this lol <div class="pvtb"><b>Barclays Premier League</b></div>hello</p>hello your funny no result. <?php $url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm"); preg_match('/\<div class\=\"pvtb\"\>\<b\>Barclays Premier League\<\/b\>\<\/div\>(.*?)\<\/p\>/i',$url, $matches); foreach($matches as $key => $value) { echo $value; } ?> Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 I just looked at the source of that page, and your regex doesn't even exist you knob Probably why it isn't displaying anything... Quote Link to comment Share on other sites More sharing options...
thebadbad Posted April 12, 2009 Share Posted April 12, 2009 What's up with all the escaping? Double quotes, angle brackets and equals signs aren't special RegEx characters. And use a different delimiter than the forward slash to get rid of even more escaping! Not that it would match what the OP is actually looking for, but '/\<div class\=\"pvtb\"\>\<b\>Barclays Premier League\<\/b\>\<\/div\>(.*?)\<\/p\>/i' can be written as '~<div class="pvtb"><b>Barclays Premier League</b></div>(.*?)</p>~i' Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Meh, I just escape everything to be sure. And what difference does using a ~ do, if you don't mind me asking? Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 12, 2009 Author Share Posted April 12, 2009 can anybody get the results lol i can not differently. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted April 12, 2009 Share Posted April 12, 2009 Meh, I just escape everything to be sure. And what difference does using a ~ do, if you don't mind me asking? Maybe I was a bit harsh, but my eyes bleed seeing all those slashes I often use a ~ as delimiter since I never use that character inside the regex pattern, and therefore never have to escape it. Much like I often single quote HTML strings, so I don't have to escape the double quotes within. Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Yeah, ditto with the single quotes thing. Plus, it's more efficient, and it looks prettier Yeah, I didn't actually know you could use ~ as a delimiter. May look into that... Quote Link to comment Share on other sites More sharing options...
thebadbad Posted April 12, 2009 Share Posted April 12, 2009 Yeah, I didn't actually know you could use ~ as a delimiter. May look into that... You can use any non-alphanumeric character as delimiter. So it's more or less always possible to use something that's not used within the regex. Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Didn't know that either Thanks for the information. 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.