regexfeedburner

regex for feedburner name


I want to get the feed name from feedburner feed url. I'm trying this:

$feed = 'http://feeds.feedburner.com/name';
$pattern = '~(?:http|https|)(?::\/\/|)?feeds.feedburner\.com/(?:clip:)?(\w+)~';
preg_match_all($pattern, $feed, $feed_name);

and this:

$feed = 'http://feeds.feedburner.com/name';
$pattern = '/http:\/\/feeds.feedburner.com\//';
$feed_name = preg_replace($pattern, '', $feed); 

And other variations but nothing...


Solution

  • Instead of regex, it is better to use parse_url PHP function:

    $feed = 'http://feeds.feedburner.com/name';
    $arr = parse_url($feed);
    echo $arr['path']; /name