我如何从 php 函数中 return 一个 php 代码?
How can I return a php code from a php function?
<?php
function A() {
return "<?php echo \"some text\"; ?>";
}
echo A();
?>
我希望在页面上看到 "some text",但我没有。
那么如何使这段代码起作用呢?提前致谢。
更新:
很抱歉描述不清楚。
我要在输入值中插入一个随机数。
<?php
function print_form() {
return "<form method=\"POST\">
<input type=\"text\" name=\"code1\" value=\" <?php echo rand(0, 999999); ?> \" />
</form>";
}
echo print_form(); ?>
伙计,你必须 return 文本不是 PHP 代码:
<?php
function A() {
return "some text";
}
echo A();
?>
连接函数的return:
return "<form method=\"POST\">
<input type=\"text\" name=\"code1\" value=\"" . rand(0, 999999) . "\" />
</form>";
<?php
function print_form() {
return '<form method="POST">
<input type="text" name="code1" value="'.rand(0, 999999).'" />
</form>';
}
echo print_form(); ?>
您要返回,所以只需连接值即可。
<?php
function A() {
return "<?php echo \"some text\"; ?>";
}
echo A();
?>
我希望在页面上看到 "some text",但我没有。 那么如何使这段代码起作用呢?提前致谢。
更新: 很抱歉描述不清楚。 我要在输入值中插入一个随机数。
<?php
function print_form() {
return "<form method=\"POST\">
<input type=\"text\" name=\"code1\" value=\" <?php echo rand(0, 999999); ?> \" />
</form>";
}
echo print_form(); ?>
伙计,你必须 return 文本不是 PHP 代码:
<?php
function A() {
return "some text";
}
echo A();
?>
连接函数的return:
return "<form method=\"POST\">
<input type=\"text\" name=\"code1\" value=\"" . rand(0, 999999) . "\" />
</form>";
<?php
function print_form() {
return '<form method="POST">
<input type="text" name="code1" value="'.rand(0, 999999).'" />
</form>';
}
echo print_form(); ?>
您要返回,所以只需连接值即可。