tags:

views:

132

answers:

3

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 portion, but either will do.

Example:

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

Desired result:

http://twitpic.com/1aso4q

or

1aso4q

Anyone able to help?

A: 

Try following regex

'/http:\/\/twitpic\.com\/\S+/i'
S.Mark
you don't need to enclose \S in square brackets
reko_t
+2  A: 
preg_match_all('#http://twitpic.com/(\w+)#', $content, $matches);

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

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