将变量传递给include

Chu*_*utt 1 php server-side-includes

的index.php

<?php
    $title = "This is the page title";
    require_once '/includes/header.php';
?>
Run Code Online (Sandbox Code Playgroud)

header.php文件

<head>
    <title><?= $title ?></title>
</head>
Run Code Online (Sandbox Code Playgroud)

产量

在此输入图像描述

Jam*_*s C 6

我认为可能没有启用短标签.尝试:

<title><?php echo $title ?></title>
Run Code Online (Sandbox Code Playgroud)

代替


she*_*ski 5

你在php.ini中启用了短标签吗?

短链接

  • `<?php = $ title?>`是无效的语法. (3认同)