PHP中不同页面的Echo变量

PHP中不同页面的Echo变量,php,Php,在PHP中,如何更改不同页面的变量 例如: header.php // For style-specific pages. echo $header_styles; 然后在类似index.php的页面中: include('header.php'); echo $header_styles = "<style></style>"; include('header.php'); echo$header_styles=“”; 我以前知道怎么做,但我完全忘记了。你需要先做

在PHP中,如何更改不同页面的变量

例如:

header.php

// For style-specific pages.
echo $header_styles;
然后在类似index.php的页面中:

include('header.php');
echo $header_styles = "<style></style>";
include('header.php');
echo$header_styles=“”;

我以前知道怎么做,但我完全忘记了。

你需要先做:

在header.php中,您将有:

<?php
echo $header_styles;
?>
<?php
    $header_styles = "<style></style>";
    include('header.php');
?>
<html>
   Your html code here
</html>

然后在需要包含标题的页面中,如index.php,您将有:

<?php
echo $header_styles;
?>
<?php
    $header_styles = "<style></style>";
    include('header.php');
?>
<html>
   Your html code here
</html>

你的html代码在这里
您需要将名称从index.html更改为index.php。然后需要在调用header.php之前设置变量,然后对其执行“echo”。
设置值时不要应用回显,因为我认为您不想打印只需要设置值的内容。

在设置回显后要更改回显吗?请在index.html中删除回显(应该是index.php,并用一个如果我理解正确的话打开,您想访问页面上的
$header\u styles
,然后稍后覆盖/更改它吗?此外,您将无法在.html页面中使用php代码。我想覆盖变量,以便无论何时在页面上包含header.php,我都可以回显该变量,并且它将包括我想要的任何内容。有点像一个页面的动态标题。好的,让我编辑“index.html”。这是一个打字错误。我是指index.php。