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
精彩评论