Home > Backend Development > PHP Tutorial > 各位大神,小弟问一个奇葩的问题

各位大神,小弟问一个奇葩的问题

WBOY
Release: 2016-06-23 13:03:10
Original
879 people have browsed it

比如有一个数组$a = array("ccc");
我的现在得到这样一个字符串 $str = '$a[0]';我怎么样才能通过得这$str的到'ccc'呢?


回复讨论(解决方案)

$a = array("ccc");
$str = $a[0]; 
echo $str . "\n"; 
echo sprintf("data is [%s]\n", $str); 

这不奇葩,php 本来就提供有这个功能

$a = array("ccc");$str = '$a[0]';eval("\$b = $str;");echo $b;echo eval("return $str;");//如果 allow_url_include = oninclude "data://," . "<?= $str?>";
Copy after login

eval 用这个主意安全

$a = array('ccc');$str = $a['0'];echo $str."\n";echo sprintf('%s',$str);
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template