有人能指出我在这里弄错了什么吗? :)PHP评估没有正确执行
<?php
$q = $_GET[q];
$acuman = <<<PARSE
input: (contains: "hello"){
output: "hello";
}
PARSE;
$acuman = str_replace("input: (contains: ", 'if(strpos(', $acuman);
$acuman = str_replace("){", ', $q) !== false) {', $acuman);
$acuman = str_replace("output: ", '$output = ', $acuman);
eval($acuman);
?>
我试图执行字符串$acuman
,已经通过各种str_replace
功能改变的heredoc
。然而,它正在做我打算做的事情,我很困惑,因为我尝试过很多不同的事情。
由于很多人似乎很困惑:我的意图是让字符串$acuman
中的代码正确执行代码。我只想让eval
功能起作用。我知道 eval是邪恶的,请停止:我只是在寻求帮助解决手头的问题。
编辑:当我呼应字符串$acuman
,这就是我得到:
if(strpos("hello", $q) !== false) { $output = "hello"; }
说什么是“没有做你打算做的事”而没有告诉你打算做什么几乎没用 – PeeHaa 2015-02-06 23:30:05
你为什么这样做?并打印出$ acuman并查看它实际包含的内容 – ElefantPhace 2015-02-06 23:31:05
您正在使用的最大错误是使用'eval()',如果包含用户输入则会加倍。我无法真正弄清楚你想在这里实现什么,但必须有更好的方法。 – 2015-02-06 23:32:46