Php 如何在单页网站中设置页面标题

Php 如何在单页网站中设置页面标题,php,Php,嗨,我有一个单页ajax网站,单页基本上是加载所有页面,我想根据当前视图设置页面标题 我试过用这个 <title><!--TITLE--></title> <? $pageContents = ob_get_contents (); // Get all the page's HTML into a string ob_end_clean (); // Wipe the buffer // Replace <!--TITLE-->

嗨,我有一个单页ajax网站,单页基本上是加载所有页面,我想根据当前视图设置页面标题

我试过用这个

<title><!--TITLE--></title>
    <?
$pageContents = ob_get_contents (); // Get all the page's HTML into a string
ob_end_clean (); // Wipe the buffer

// Replace <!--TITLE--> with $pageTitle variable contents, and print the HTML
echo str_replace ('<!--TITLE-->', $pageTitle, $pageContents);
?>

在javascript中:

document.title = "New Title";

变量$pageTitle似乎是在使用str_replace进行替换后定义的。
也许您可以发布更多代码来查看问题所在

您能打印HTML吗? 对我来说很好

print "<TITLE>".$pageTitle."</TITLE>";
打印“$pageTitle.”;
然后只需删除设置标题的任何其他代码:

例如:



  • 您是否调用了
    ob_start()?尝试移动您的
    
    print "<TITLE>".$pageTitle."</TITLE>";
    
    <title><!--TITLE--></title>
    
    <?
    $TITLE[home]="Saunders-Solutions Freelance Design and Development";
    $TITLE[about]="About Saunders-Solutions Freelance Design and Development";
    ?>
    
    <title><?=$TITLE[$_GET[page]]?></title>
    
    <li class="menu-link">
            <a href="index.php?page=home"><img src="images/menu/home.png" width="72" height="72" alt="Home" />Home</a>            
        </li>
        <li class="menu-link">
            <a href="index.php?page=about"><img src="images/menu/about.png" width="72" height="72" alt="About" />About</a>
    
        </li>