Forums

Isolating part of a URL with PHP (2 posts)

  1. kasperbs
    Member
    Posted 3 years ago #

    Hi,
    I have a custom field that will include a link similar to this:
    http://farm3.static.flickr.com/2085/2177060015_258bcfaff9_m.jpg

    The variable will be:
    $url = http://farm3.static.flickr.com/2085/2177060015_258bcfaff9_m.jpg

    I need to somehow isolate the following part and put it in a variable of its own:
    http://farm3.static.flickr.com/2085/*2177060015*_258bcfaff9_m.jpg

    so I would end up with something like this:
    $var = '2177060015'

    Is there any way to do that?

  2. Michael Fields
    Theme Wrangler
    Posted 3 years ago #

    The following code is untested, but the theory should yeild the results you are looking for.

    $url = 'http://farm3.static.flickr.com/2085/2177060015_258bcfaff9_m.jpg';
    $filename = basename( $url );
    $parts = explode( '_', $filename );
    $var = $parts[0];

    Resources
    http://us3.php.net/manual/en/function.basename.php
    http://us2.php.net/explode

Topic Closed

This topic has been closed to new replies.

About this Topic