1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

what's wrong in this code ?

Discussion in 'PHP' started by moshxsoft, Aug 16, 2010.

  1. #1
    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:
     
    moshxsoft, Aug 16, 2010 IP
  2. Kudo

    Kudo Peon

    Messages:
    933
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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?
     
    Kudo, Aug 16, 2010 IP
  3. moshxsoft

    moshxsoft Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes, i want to get last program by rss
    but my code bring one program this is wrong
     
    moshxsoft, Aug 16, 2010 IP
  4. Kudo

    Kudo Peon

    Messages:
    933
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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:
     
    Kudo, Aug 16, 2010 IP
  5. moshxsoft

    moshxsoft Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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:
     
    moshxsoft, Aug 16, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    <?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:
     
    danx10, Aug 16, 2010 IP
  7. Kudo

    Kudo Peon

    Messages:
    933
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #7
    haha ... that's the difference between a pro and a novice xD ... well done danx10:))
     
    Kudo, Aug 16, 2010 IP
  8. moshxsoft

    moshxsoft Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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, Aug 16, 2010 IP
  9. Kudo

    Kudo Peon

    Messages:
    933
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #9
    @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 !!!
     
    Kudo, Aug 16, 2010 IP