Search code examples
phparraysparsingstring-parsing

String to array


users of site can fill in form input something like that - array(1,23,4,5) and so on. Can be variants like array(array('qwe')) and others.

How i can convert all type of strings like specified to regulary arrays

So i need to convert

array(
    "String" => "I am a string", 
    "bool" => true, 
    "int" => 99, 
    "float" => 9.45, 
    "array" => array()
);

To

array(6) {
  ["String"]=>
  string(13) "I am a string"
  ["bool"]=>
  bool(true)
  ["int"]=>
  int(99)
  ["float"]=>
  float(9.45)
  ["array"]=>
  array(0) {
  }
}

Also i cannot use eval couse of security reasons

P.S. Sorry for my bad English.


Solution

  • I used an PHPSandbox to parse an php and get all variations within an parsing arrays.

    I use code from https://github.com/fieryprophet/php-sandbox