[Solved] php explode where no spaces etc [closed]


I’m assuming those are location names “France”, “Paris”, “Great Britain”, etc…

Here is one possible solution:

$places = array("FR", "PAR", "GB", "ASD");
$string = "FRPARGBASD";

$tokens = array();
while (strlen($string) > 0) {
   $next_token = "";
   $i = 0;
   while ($next_token == "") {
      if (substr($string, 0, strlen($places[$i])) == $places[$i]) {
         $next_token = $places[$i];
      }
   }
   $tokens[] = $next_token;
   $string = substr($string, strlen($next_token));
}

var_dump($tokens);

Hope that helps

4

solved php explode where no spaces etc [closed]