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]); ?> Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/ 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 ......... Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807928 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; } ?> Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807933 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Idn't that what I put ??? Lol Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807936 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; } ?> Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807941 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? Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807947 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; } ?> Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807949 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. Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807951 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; } ?> Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807953 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... Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807956 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' Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807959 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? Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807961 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. Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807965 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. Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-807995 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... Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-808015 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. Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-808023 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. Link to comment https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/#findComment-808026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.