Split url to trailing slash

I'm looking for a way to split a Twitter permalink string into its final slash, so I can save tweet_id. Two examples:

http://twitter.com/bloombergnews/status/55231572781170688
http://twitter.com/cnn/status/55231572781170688

Each URL has a similar format:

http://twitter.com/<screen_name>/status/<id_str>

With what regular expression will I easily write every time?

+5
source share
2 answers

This is not a job for regular expressions, IMHO.

I would do this:

$parts = explode('/', rtrim($url, '/'));
$id_str = array_pop($parts);
+21
source

REGX? Yes; simple one liner.

$ url = 'http://twitter.com/bloombergnews/status/55231572781170688';


Perl

($ f1 = $ url) = ~ s /^.*\///;

print $ f1;


Php

$ f1 = preg_replace ("/^.*\//",""$$ url);

echo $ f1;

EDIT: backslash did not show; fixed in the edit box by double \\ (wierd!)

+2
source

All Articles