是否可以使用GET数据在PHP中调用特定函数? [重复]
This question already has an answer here:
I have a file functions.php which has multiple functions like:
function do_this(){
}
function do_that(){
}
Now, I am thinking doing something weird like calling that function from URL:
functions.php?func=do_that
Now, I added this lines of code to functions.php
if(isset($_GET["func"])){
$func = $_GET["func"];
//How to call that function with name "$func"
}
Any great brains out there? Let me know. If that's not possible, then also lemme know. Coz I have to think of a new approach in my work.
</div>
此问题已经存在 这里有一个答案: p>
-
如何从存储在变量中的字符串调用PHP函数
15 answers
span>
li>
ul>
div>
我有一个文件 functions.php strong>,它有多个函数,如: p>
function do_this(){ } 函数do_that(){ } code> pre>
现在,我正在考虑做一些奇怪的事情,比如从URL调用该函数: p>
functions.php? func strong> = do_that em> p> blockquote>
现在,我将这行代码添加到 functions.php strong > p>
如果(isset($ _ GET [ “FUNC”] )){ $ func = $ _GET [“func”]; //如何调用名为“$ func”的函数 } code> pre>
那里有什么大脑? 让我知道。 如果这不可能,那么也知道。 因为我必须在工作中考虑一种新的方法。 p> div>
All you need to do is to call the function as you get the $_GET variables like this:
if(isset($_GET["func"])){
$func = $_GET["func"];
$func();
}