[英]In PHP how can access a property in an included file that was defined in the calling file?
如果我有兩個文件
main.php
<?php
$title = "thisTitle";
include $_SERVER['DOCUMENT_ROOT']."/aatemplate.php";
?>
aatemplate.php
<html lang="en">
<head>
<?php include $_SERVER['DOCUMENT_ROOT']."/common/head.php";?>
<title>$title</title>
</head>
</html>
如何使模板文件中的'$ title'替換為main.php中設置的$ title,以便它變為:
<title>thisTitle</title>
如果您包含一個文件,該文件將訪問主文件和以前包含的文件變量。
更改
<title>$title</title>
至
<title><?php echo $title; ?></title>
您可以引用使用echo語句聲明的PHP變量
替換為<?php echo $title; ?>
<?php echo $title; ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.