Вопрос

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.

Это было полезно?

Решение 2

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

Другие советы

The only way to do this without eval() would be to write it out to a temp file and include it (just as risky and may be invalid so it generates a parse error):

file_put_contents('temp.php', '<?php $array = ' . $_POST['field'] . '; ?>');
include('temp.php');
var_dump($array);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top