![](/img/trans.png)
[英]PHP - How to get a variable from another php file with a variable variable
[英]How to get a PHP variable value from another PHP file?
如何從另一個.php文件中獲取值,可以幫助我解決此問題:
<html>
<head>
</head>
<body>
<form name='answer' action="file2.php" method="post">
<input type="text" name="what">
<input type="submit" value="Login">
</form>
<div><?php echo $answer; ?></div>
</body>
</html>
並且file2.php文件的代碼如下:
<?php
if ($_POST['what']==animal){
$answer="dog";
}else{
$answer= "not animal";
}
我想知道如何通過按鈕獲取變量$ answer的值,然后在行中輸入以下內容:
使用require_once()
在文件中包含file2.php,然后在文件中訪問file2.php中的變量。
require_once("path of file2.php");
echo $answer;
只需使用要求
<?php require 'file2.php'; ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.