开发者

PHP: Get multiple Strings between

I have the following string:

$string = '"http://i.stack.imgur.com/?oapQok.png" blabla "http://i.stack.imgur.com/p9*xp.png" blabla "http://i.stack.imgur.com/papsyewxp.jpg"'

I now want to get the following开发者_JS百科:

array(3) {
  [0] => string("?oapQok.png")
  [1] => string("p9*xp.png")
  [2] => string("papsyewxp.jpg")
}

The problem: The length varies, there are 'strange' --> *$? chars in it, etc...

Can you explain how to fix it?


Try the following regular expression:

"http:\/\/i.imgur.com\/([^"]+)"

Also see the php documentation on preg_match_all to pull out the captures.


$string = '"http://i.stack.imgur.com/?oapQok.png" blabla "http://i.stack.imgur.com/p9*xp.png" blabla "http://i.stack.imgur.com/papsyewxp.jpg"';

$matches = array();
preg_match_all('/"http:\/\/i.imgur.com\/([^"]+)"/', $string, $matches);

var_dump($matches[1]);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜