2

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

How can I do it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
designvoid
  • 431
  • 1
  • 6
  • 19

3 Answers3

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

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

SilentGhost
  • 307,395
  • 66
  • 306
  • 293
reko_t
  • 55,302
  • 10
  • 87
  • 77
0

Try following regex

'/http:\/\/twitpic\.com\/\S+/i'
YOU
  • 120,166
  • 34
  • 186
  • 219
0
$str = "blah blah blah http://twitpic.com/1aso4q blah blah";
$s = explode(" ",$str);
print_r( preg_grep('/http:\/\/twitpic.com/',$s) );
ghostdog74
  • 327,991
  • 56
  • 259
  • 343