SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Location
    The Wirral, England
    Posts
    1,294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed with regex

    I'm trying to retrieve a certain url from a string, the string being, with the desired part in bold.

    <video_details>
    <author>youtubeuser</author>
    <title>My Trip to California</title>
    <rating_avg>3.25</rating_avg>
    <rating_count>10</rating_count>
    <tags>california trip redwoods</tags>
    <description>This video shows some highlights of my trip to California last year.</description>
    <update_time>1129803584</update_time> <!-- UNIX time, secs since 1/1/70 -->
    <view_count>7</view_count>
    <upload_time>1127760809</upload_time> <!-- UNIX time, secs since 1/1/70 -->
    <length_seconds>8</length_seconds>
    <recording_date>None</recording_date>
    <recording_location/>
    <recording_country/>
    <comment_list>
    <comment>
    <author>steve</author>
    <text>asdfasdf</text>
    <time>1129773022</time>
    </comment>
    </comment_list>
    <channel_list>
    <channel>Humor</channel>
    <channel>Odd & Outrageous</channel>
    </channel_list>
    <thumbnail_url>http://static205.youtube.com/vi/bkZHmZmZUJk/2.jpg</thumbnail_url>
    </video_details>

    The PHP I've tried is as follow, where $ytapi contains the above string (I've checked this):
    PHP Code:
    IF (preg_match("#^(.*)(<thumbnail_url>)([a-zA-Z0-9:/.\-]+)(</thumbnail_url>)(.*)$#",$ytapi,$thumbnail)) {
    echo (
    $thumbnail['3']);

    But it doesn't want to match. I can't see where I'm going wrong, any ideas? Thanks
    "The proper function of man is to live - not to exist."
    Get a Free TomTom


  2. #2
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Location
    The Wirral, England
    Posts
    1,294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't worry I sorted it, if anyone's interested the regex that works is...

    preg_match("#<thumbnail_url>([a-zA-Z0-9:/.\-]+)</thumbnail_url>#",$ytapi,$thumbnail)

    Feeling it may be something to do with the multiline nature of the string.
    "The proper function of man is to live - not to exist."
    Get a Free TomTom



Bookmarks

Posting Permissions

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