Lytheum Posted December 8, 2007 Share Posted December 8, 2007 I need to pull some info off a certain website that is setup like this: <b>Blah1:</b> 11<br/> <b>Blah2:</b> 22<br/> <b>Blah3:</b> 33<br/> <b>Blah4:</b> 44<br/> <b>Blah5:</b> 55<br/> So I should be able to try: echo "$blah1"; //value of 11 echo "blah5"; //value of 55 My code which doesn't work at all, hopefully somebody can improve on it: // Get page $url = "http://url.url.url"; $data = implode("", file($url)); // Get content items preg_match_all ("/<\/b>([^`]*?)<br\/>/", $data, $matches); // Loop through each content item foreach ($matches[0] as $match) { // First, get title preg_match ("/<b>Blah1:<\/b>([^`]*?)<br\/>/", $match, $temp); $title = $temp['1']; $title = strip_tags($title); $title = trim($title); } echo "$blah1"; Thanks for any future help, if you still don't understand lemme know. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted December 8, 2007 Share Posted December 8, 2007 Try: <?php $str="<b>Blah1:</b> 11<br/> <b>Blah2:</b> 22<br/> <b>Blah3:</b> 33<br/> <b>Blah4:</b> 44<br/> <b>Blah5:</b> 55<br/>"; preg_match_all('|Blah([0-9]).*?([0-9]+)|',$str,$matches); $blah = array(); foreach($matches[1] as $k => $v){ $blah[$v] = $matches[2][$k]; } echo $blah[1]; //11 echo $blah[5]; //55 ?> Quote Link to comment Share on other sites More sharing options...
Lytheum Posted December 8, 2007 Author Share Posted December 8, 2007 Awesome that does work. Now just one more question if you could. How do I do it when there is no pattern to follow? For instance: <?php $str="<b>blah:</b> 11<br/> <b>blah:</b> 22<br/> <b>blah:</b> 33<br/> <b>blah:</b> 44<br/> <b>blah:</b> 55<br/> "; ?> 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.