php如何包含没有标题的页面

时间:2013-08-01 10:42:16

标签: php html header include

我想在页面顶部添加一个页面。

但是当我这样做的时候。我的标题被替换为页眉。

例如,我的标题被替换为页面标题。

我该如何解决?

包含的页面标题:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Retrieving video details</title>
<style>
img {
  padding: 2px; 
  margin-bottom: 15px;
  border: solid 1px silver; 
}
td {
  vertical-align: top;
}
</style>
  </head>

2 个答案:

答案 0 :(得分:1)

您最好的选择是删除该页面的标题,以便它不会覆盖您的标题,或者在加载包含的文件后设置标题以使您的标题覆盖包含的页面标题。 如果你从另一个域外部获取它,我担心你会被卡住。

修改:如果可以,请从包含页面的源代码中删除<title>标记。否则,请包含该文件并在其后设置<title>Your Title</title>

答案 1 :(得分:1)

对于这个问题,我有一个解决方案。

  1. 创建一个页面,并在该页面内创建一个函数

     <?php 
     function createHeader($title,$desc1,$keywords)
     { 
         ?>
     <!DOCTYPE html>
     <html lang="zxx">
     <head>
        <title>.....</title>
        <link>--------</link>
       -----------------------
     </head>
    
  2. 调用此函数。例如

    <?php 
            //I include this page in my another page that's why i write this condition
        if($news!="tech-headlines"){  
            include'header.php';  // include header file in this page
            createHeader();       // call header function
        }
      ?>
    
  3. 在体内编写代码

    <body>
     -------------
     -------------
    </body>
    
  4. 我已将此页面包括在另一个页面中,但标题除外(只能在主体代码内部访问),或者当我单独运行此页面时,它将包含标题运行