I have a string:

PEKKACard.pngGolemCard.pngFreezeCard.pngBombTowerCard.pngHogRiderCard.pngGiantCard.pngBomberCard.pngElixirCollectorCard.pngplease

And png files can be called whatever you like, but the format is always png. Instead of "please" there can be any text. How do I convert this string to an array to make it:

$arr = [PEKKACard.png; GolemCard.png; FreezeCard.png; BombTowerCard.png; HogRiderCard.png; GiantCard.png; BomberCard.png; ElixirCollectorCard.png; please] 

That is, $ arr [0] should be PEKKACard.png. And for example, $ arr [8] should be please. And by the way, pictures in the pn format are always 8 pieces and after them comes any text. PS: If you know how to do this, enter the code, not the technology :) Many thanks in advance!

    2 answers 2

    Here's another option:

     $str="PEKKACard.pngGolemCard.pngFreezeCard.pngBombTowerCard.pngHogRiderCard.pngGiantCard.pngBomberCard.pngElixirCollectorCard.pngplease"; preg_match("/((?:.*?)\.png)((?1))((?1))((?1))((?1))((?1))((?1))((?1))(.*)/", $str, $matches); var_dump($matches); 

    Output:

     array(10) { [0]=> string(129) "PEKKACard.pngGolemCard.pngFreezeCard.pngBombTowerCard.pngHogRiderCard.pngGiantCard.pngBomberCard.pngElixirCollectorCard.pngplease" [1]=> string(13) "PEKKACard.png" [2]=> string(13) "GolemCard.png" [3]=> string(14) "FreezeCard.png" [4]=> string(17) "BombTowerCard.png" [5]=> string(16) "HogRiderCard.png" [6]=> string(13) "GiantCard.png" [7]=> string(14) "BomberCard.png" [8]=> string(23) "ElixirCollectorCard.png" [9]=> string(6) "please" } 

    http://sandbox.onlinephpfunctions.com/code/35cd11e08cecbad1271dcfc45d95c7b112907994

    https://regex101.com/r/tV7rM5/1

       $str="PEKKACard.pngGolemCard.pngFreezeCard.pngBombTowerCard.pngHogRiderCard.pngGiantCard.pngBomberCard.pngElixirCollectorCard.pngplease"; $arr=preg_split("/\.png\K/",$str); var_dump($arr); 

      \K in this regular expression allows you not to include .png in a match and thus not cut it out of the text, as split does normally.