我希望能够检查一个文本字符串,并提取一个TwitPic网址,如果它在字符串中出现,最终我希望只是代码部分,但任何一个都可以。
示例:
"blah blah blah http://twitpic.com/1aso4q blah blah"期望的结果:
http://twitpic.com/1aso4q或
1aso4q我该怎么做呢?
发布于 2010-03-25 19:46:50
preg_match_all('#http://twitpic.com/(\w+)#', $content, $matches);然后,您将拥有$matches[1]中的所有代码。
发布于 2010-03-25 19:44:52
尝试使用正则表达式
'/http:\/\/twitpic\.com\/\S+/i'发布于 2010-03-25 19:54:34
$str = "blah blah blah http://twitpic.com/1aso4q blah blah";
$s = explode(" ",$str);
print_r( preg_grep('/http:\/\/twitpic.com/',$s) );https://stackoverflow.com/questions/2515087
复制相似问题