hello what's wrong in this code ? this code to bring last program from rss from softpedia <?php $topic=file_get_contents('http://www.softpedia.com/backend.xml'); while( $count=strpos($topic,'href="http://www.softpedia.com/get',$count+1)) { $take=strstr($topic,'href="http://www.softpedia.com/get'); $count1=strpos($take,'.shtml'); $title=substr($take,+6,$count1); echo $title.'<br />'; } ?> PHP:
I can't understand what exactly you are trying to do ... I tested the code myself and it printed out about 20 lines with the same link ... so, do you want to get the last 20 programs from this URL or what?
Here is a better & tested code from me my friend ... it makes an array of titles and links ... $titles = Titles array & $links = links array <?php $topic=file_get_contents('http://www.softpedia.com/backend.xml'); $links = array(); $links1 = array(); $links2 = array(); $titles = array(); $titles1 = array(); $titles2 = array(); /** * MAKE AN ARRAY OF TITLES */ $titles1 = explode("<title>",$topic); for($x=0;$x<count($titles1);$x++) { $titles2[] = explode("</title>",$titles1[$x]); }; for($y=3;$y<count($titles2);$y++) { $titles[] = $titles2[$y][0]; } /** * END OF MAKE AN ARRAY OF TITLES */ /** * END OF MAKE AN ARRAY OF LINKS */ $links1 = explode("<link>",$topic); for($x=0;$x<count($links1);$x++) { $links2[] = explode("</link>",$links1[$x]); }; for($y=3;$y<count($links2);$y++) { $links[] = $links2[$y][0]; } /** * END OF MAKE AN ARRAY OF LINKS */ //print_r($titles); //print_r($links); ?> PHP:
thanks, it's work but can you modify on this code <?php $topic=file_get_contents('http://www.softpedia.com/backend.xml'); while( $count=strpos($topic,'href="http://www.softpedia.com/get',$count+1)) { $take=strstr($topic,'href="http://www.softpedia.com/get'); $count1=strpos($take,'.shtml'); $title=substr($take,+6,$count1); echo $title.'<br />'; } ?> PHP:
<?php $xml = simplexml_load_file('http://www.softpedia.com/backend.xml'); foreach ($xml->channel->item as $arr) { foreach ($arr->title as $title) { echo $title . '<br />'; } } ?> PHP:
can you modify on this code <?php $topic=file_get_contents('http://www.softpedia.com/backend.xml'); while( $count=strpos($topic,'href="http://www.softpedia.com/get',$count+1)) { $take=strstr($topic,'href="http://www.softpedia.com/get'); $count1=strpos($take,'.shtml'); $title=substr($take,+6,$count1); echo $title.'<br />'; } ?> PHP:
@moshxsoft Your code won't work, simply because there is no point of increasing the number of INT offset in strpos function ... not matter whether it's 0 or 1000 it will always print out the same result !!!