我正在尝试使用include_once()php api将文件(myfile.php)的内容加载到另一个(index.php)中。但它没有加载内容。
// contents inside index page
if(include_once('myfile.php')){
echo D; // this is working
echo $b; // this is not working
} else {
echo "unable to include the file";
}
// contents inside myfile.php
define('D', '123');
$b = "abcd";
答案 0 :(得分:2)
您可能没有正确包含它。
您可以找到in the documentation:
<?php
// won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('')
if (include('vars.php') == 'OK') {
echo 'OK';
}
// works
if ((include 'vars.php') == 'OK') {
echo 'OK';
}
?>
答案 1 :(得分:0)
成功时,Include_once不会返回true,如manual中所述。
你需要使用if((包括'myfile.php')=='OK'){....}