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.

Parsing the Blogger rss feed - how?

Discussion in 'XML & RSS' started by piniyini, Nov 17, 2004.

  1. #1
    Hi guys, I'm trying to parse my blog feed which is at www.toseef.com/atom.xml

    I've managed to get the title of the first ten posts, like I wanted, using the following code:

    
    $html = file_get_contents("http://www.toseef.com/atom.xml");
    $patterns = "/<title mode=\"escaped\" type=\"text\/html\">(.*)<\/title>/Uis"; 
    preg_match_all($patterns, $html, $matches); 
    
    print '<pre>'; 
    
    $i = 1;
    while ($i < 11) {
    print_r($matches[1][$i]); $i++; echo("<br>"); } exit('</pre>');
    
    PHP:
    The result can be seen here www.thewizsite.com/img.htm - I've managed to do this because the pattern is matched with an open and close tag.

    Getting the link to each post is much more difficult as the code to match is as follows:
    <link href="http://www.toseef.com/2004/11/add-your-link-to-this-site-and-others.html" rel="alternate" title="Add Your Link To This Site (and others)" type="text/html"/>
    Code (markup):
    Obviously, I need the text that is in the href section - How do I go about this? I've tried similar stuff to my previous post but I'm not getting anywhere.

    Help?
     
    piniyini, Nov 17, 2004 IP
  2. xml

    xml Peon

    Messages:
    254
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have u tried something like:

    preg_match('/<link.*href=["|\'](.*)["|\']/i', $xml, $matches);
    PHP:
     
    xml, Nov 17, 2004 IP
  3. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #3
    You would be better off using PHP's WML parsing ability...

    $parser = xml_parser_create('UTF-8');
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); 
    xml_parse_into_struct($parser, $data, $vals, $index); 
    xml_parser_free($parser);
    PHP:
    for example
     
    digitalpoint, Nov 17, 2004 IP
  4. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #4
    Err, Shawn I dont know what you mean, could you give me an example where the code is in use?

    And XML I tried code similar to that and cant get it to work ...

    I *really* want this to work so that I can display my posts on other sites
     
    piniyini, Nov 18, 2004 IP
  5. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #5
    digitalpoint, Nov 18, 2004 IP
  6. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #6
    piniyini, Nov 18, 2004 IP