Jump to content

Loop the results


egturnkey

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.