繁体   English   中英

更改包含的php文件中的文本

[英]change text inside a included php-file

我有一个HTML / PHP页面,从数据库中检索数据。 使用PHP包括我将head.php和footer.php结合在一起。 在我的index.php中,我将其包含在文件的开头和结尾。 但是现在我遇到了一个问题,因为根据index.php(或任何其他文件)中从数据库检索到的信息,我想更改页面的<h1></h1> ,但是那部分在头。 PHP。

在已经包含的.php文件中更改<h1>中的文本的最简单方法是什么? 编辑:可以用PHP吗? 我可以使用HTML,还是必须使用JavaScript?

head.php

<html>
<head></head>
<body>
//A lot of code that makes the frame of my page
<h1 id="pagetitle"></h1>
//more code that makes the frame of my page

的index.php

include 'head.php';

//..retrieve information from database
//..change text inside <h1> inside head.php


include 'footer.php';

footer.php

</body>
</html>

一旦PHP解析并包含了您的标头代码的内容,那就完成了。 PHP将不会在以后重新解析它。 您需要一些JS或JQuery来返回并替换代码中的值,例如,替换为ID。

例如(index.php内的JS):

document.getElementById("pagetitle").innerHTML = "<?php echo $myTitleVariable ;  ?>";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM