Search code examples
phpstringspecial-characters

PHP: Get multiple Strings between


I have the following string:

$string = '"https://i.sstatic.net/?oapQok.png" blabla "https://i.sstatic.net/p9*xp.png" blabla "https://i.sstatic.net/papsyewxp.jpg"'

I now want to get the following:

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?


Solution

  • Try the following regular expression:

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

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