开发者

PHP regular expression to extract TwitPic link/code if present

开发者 https://www.devze.com 2022-12-25 02:35 出处:网络
I would like to be able to check a string of text and extract a TwitPic URL if it is present in the string, ultimately I would like just the code porti开发者_StackOverflowon, but either will do.

I would like to be able to check a string of text and extract a TwitPic URL if it is present in the string, ultimately I would like just the code porti开发者_StackOverflowon, but either will do.

Example:

"blah blah blah http://twitpic.com/1aso4q blah blah"

Desired result:

http://twitpic.com/1aso4q

or

1aso4q

How can I do it?


preg_match_all('#http://twitpic.com/(\w+)#', $content, $matches);

You will then have all the codes in $matches[1].


Try following regex

'/http:\/\/twitpic\.com\/\S+/i'


$str = "blah blah blah http://twitpic.com/1aso4q blah blah";
$s = explode(" ",$str);
print_r( preg_grep('/http:\/\/twitpic.com/',$s) );
0

精彩评论

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