Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts

    variable from xml

    http://feeds.spreadfirefox.com/downloads/firefox.xml
    Could someone please point me to a tutorial/ give me a script to find the value of description? I dont want to learn how to interact fully between xml and php yet just how to get this little thing done.

    The one and only,
    ILLINI
    Why not thank me?

    http://adamsworld.name

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I did this recently and just used a bit of simple regex...

    PHP Code:
    <?php
    $content 
    =
    file_get_contents("http://feeds.spreadfirefox.com/downloads/firefox.xml");

    $pattern '@(<description>).*?(?=</description>)@';
    preg_match_all($pattern$content$description);

    $description substr($description[0][0], 13);

    echo 
    'The description is ' $description;
    ?>
    ~Phil~

  • #3
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Well that works great except for one problem... Is is possible to look for the second desctiption? The one with the number in it?
    thanks

    The one and only,
    ILLINI
    Why not thank me?

    http://adamsworld.name

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yes...

    Code:
    <?php
    $content =
    file_get_contents("http://feeds.spreadfirefox.com/downloads/firefox.xml");
    
    $pattern = '@(<description>).*?(?=</description>)@';
    preg_match_all($pattern, $content, $matches);
    
    $description = substr($matches[0][0], 13);
    $description2 = substr($matches[0][1], 13);
    
    echo 'The description is ' . $description . ' and the 2nd description
    is ' . $description2;
    ?>
    preg_match_all produces a 2d array. You can do something like...

    Code:
    echo '<pre>'; print_r($matches); echo '</pre>';
    Just after the preg_match_all. This will give you an overview of the array created. The way 2,3,4,5 even 8934880203D arrays work, is you have arrays inside arrays inside arrays etc. This is really handy in some cases. You can see in my code, $matches[0][1]. This means item 0 of array 1 and item 1 of array 2. If you had a 5D array, you could do something like $matches[2][5][9][4][7].

    Anywhooo, hope this helps

    ~Phil~

  • #5
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    cool man thanks works like a charm.
    thanks


    The one and only,
    ILLINI
    Why not thank me?

    http://adamsworld.name

  • #6
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,846
    Thanks
    21
    Thanked 157 Times in 148 Posts
    quick question...in your regex pattern, what is the red part doing exactly:

    $pattern = '@(<description>).*?(?=</description>)@';
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #7
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ?= takes it before that point. i.e. If you had <description>hello hello hello</description> and didn't use a ?=, you'd get <description>hello hello hello</description> output. If you do use a ?=, you get <description>hello hello hello output. My regex isn't the best, and if someone would advise me on how to do a similar thing with the initial <description>, rather than having to substr it out, that would be very handy.

    ~Phil~


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •