有人能指出我在這裏弄錯了什麼嗎? :)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