Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthormista3
    • CommentTimeApr 5th 2007 edited
     permalink
    I need some php to extract the latest addition to my Twitter feed...

    Eg, the 'description' element from within 'item' from http://twitter.com/statuses/user_timeline.rss?count=1

    The below gives me the first description, where $result is the contents of the xml feed:
    $description=preg_match("/<description>(.*?)<\/description>/", $result, $matchtitle);
    $ticker="$matchtitle[1]";


    But I need the second instance of description, eg 'James Greig: Wondering how many people use twitter!?!?!?!'

    Can I get this using reg_match_all? I want to keep this simple and not use an external xml parsing script, if poss :)
    • CommentAuthormista3
    • CommentTimeApr 5th 2007 edited
     permalink
    Think I got it:

    $description=preg_match_all("/<description>(.*?)<\/description>/", $result, $matchtitle);
    print '<h3>'.substr($matchtitle[0][1],13,-14).'</h3>';


    Is there a better way to do this though?

    My entire script looks like this now: (Output here)


    <?php

    function getLatestTwitter($username,$password) {

    $host = "http://twitter.com/statuses/user_timeline.rss?count=1";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $host);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);
    $result = curl_exec($ch);
    curl_close($ch);

    $description=preg_match_all("/<description>(.*?)<\/description>/", $result, $matchtitle);
    print '<h3>'.substr($matchtitle[0][1],13,-14).'</h3>';

    }

    getLatestTwitter("3stripe","passwordgoeshere");

    ?>
    • CommentAuthorMatt
    • CommentTimeApr 6th 2007
     permalink
    I just use lastRSS, I really suck at regular expressions.
Add your comments
    Username Password
  • Format comments as (Help)