egturnkey Posted October 3, 2010 Share Posted October 3, 2010 Hello dear friends, I've made littel code that fetch the categories name from an software website $text= file_get_contents('http://win.softpedia.com/'); // it make win.softpedia as text code $start = strstr("$text",'<ul id="windows_cat">'); // search inside to that start point $end = strpos("$start",'" title="'); // end at it to that end point $cat = substr($start,66,$end-66); echo "$cat<hr>"; it will show now the categories but it only shows the 1st one Antivirus/ how then loop it to find next and next and so on to show me the list of the categories ! thanks Link to comment https://forums.phpfreaks.com/topic/215042-loop-the-results/ Share on other sites More sharing options...
BlueSkyIS Posted October 3, 2010 Share Posted October 3, 2010 you might consider using preg_match_all() to get all matches in one shot. http://php.net/manual/en/function.preg-match-all.php if you want to loop, i would find the first match, truncate the string, find the next match, truncate the string, etc. (looping) until no more matches are found or the string is gone. i would use a while loop. Link to comment https://forums.phpfreaks.com/topic/215042-loop-the-results/#findComment-1118553 Share on other sites More sharing options...
PaulRyan Posted October 3, 2010 Share Posted October 3, 2010 I believe this will work, it will return all catergories within an array. <?php $text= file_get_contents('http://win.softpedia.com/'); $catergories = explode('<ul id="windows_cat">',$text); $catergories = explode('</ul>',$catergories[1]); $catergories = trim(preg_replace('/\<li><a href="http:\/\/[a-zA-Z-.]{1,}\/[a-zA-Z-]{1,}\/[a-zA-Z-]{1,}\/\"\stitle="[a-zA-Z-\/\s]{1,}\"\s>([a-zA-Z-\/\s]{1,})\<\/a><\/li>/', "$1|", $catergories[0])); $catergories = array_slice(explode('|',$catergories),0,21); print_r($catergories); ?> Could possibly be shortened down but anyways, tell me how it goes bud. Regards, Paul. Link to comment https://forums.phpfreaks.com/topic/215042-loop-the-results/#findComment-1118563 Share on other sites More sharing options...
egturnkey Posted October 3, 2010 Author Share Posted October 3, 2010 you might consider using preg_match_all() to get all matches in one shot. I will also try this, thanks for that idea. I believe this will work, it will return all catergories within an array. Regards, Paul. Amazing, it works perfect thank you so much it has fixed 2 main problems i have cause i was going to import all categories then makes it into array now with your code, you've made very short way to me thanks Link to comment https://forums.phpfreaks.com/topic/215042-loop-the-results/#findComment-1118570 Share on other sites More sharing options...
PaulRyan Posted October 3, 2010 Share Posted October 3, 2010 No problem egturnkey, if you need anything just post back Thanks, Paul. Link to comment https://forums.phpfreaks.com/topic/215042-loop-the-results/#findComment-1118577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.