开发者

Extract Twitter username with PHP

Say, I have a direct URL to a Twitter post, like

$url="http://twitter.com/#!/YourName/status/01234567890123456";

or

$url="http://twitter.com/YourName/status/01234567890123456";

Could you please advise the simplest way in PHP (regexp, i suppose) to extract YourName out of these strings that looks something like that:

$account= ??? (???,$url);开发者_如何学编程

Thanks.


You can use a regular expression to do this.

Something along the lines of:

preg_match("/http:\/\/twitter.com\/(#!\/)?([^\/]*)/", $url, $matches);
var_dump($matches);

I have created a rubular here: http://rubular.com/r/YNw7PVSxqS

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜