2014-09-26 103 views
-1

我希望關鍵字和描述元標記是動態寫入的。我看到這個thead,但我不能對metatags做同樣的事情。
這裏是我的代碼:http://runnable.com/VCSYsvEy0xov2fNi/my-for-phpPHP元標記描述和關鍵字動態

的index.php

<?php 
ob_start(); // Buffer output 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 

<head> 
<title><!--TITLE--></title> 
    <meta http-equiv="Content-Language" content="it" /> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
    <meta name="keywords" content="<!--KEYWORDS-->" /> 
    <link rel="stylesheet" type="text/css" href="template/style.css"> 
    <script type="text/javascript" src="config/expand.js"></script> 
    <script type="text/javascript" src="config/jquery-1.5.2.min.js"></script> 
    <script type="text/javascript" src="config/scriptbreaker-multiple-accordion-1.js"></script> 
    <script language="JavaScript"> 
     $(document).ready(function() { 
      $(".topnav").accordion({ 
      accordion:false, 
      speed: 500, 
      closedSign: '[+]', 
      openedSign: '[-]' 
      }); 
     }); 
    </script> 
</head> 
<body> 
     <div id="container"> 
      <div id="banner"><?php include('template/banner.php') ?></div> 
      <!--<div id="nav_main"><?php include('template/nav_main.php') ?></div> --> 
      <div id="navigation_left"><?php include("template/link_left.php") ?></div>  
      <div id="navigation_right" align="left"><?php include("template/link_right.php") ?></div>        
      <div id="content"><?php include("$page.php") ?> </div> 
      <div id="footer"><?php include('template/footer.php') ?></div> 
     </div> 
</body> 
</html> 
<?php 
$pageContents = ob_get_contents(); // Get all the page's HTML into a string 
$pageKeywords = ob_get_contents(); 
ob_end_clean(); // Wipe the buffer 

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

?> 

home.php(主頁)

<?php $pageTitle = 'Full Metal Panic Italy | Home';?> 
<?php $pageKey = 'full, metal, panic, fmp, fumoffu, the second raid, spoiler, mithril, amalgam, sigma';?> 
<p style="background:#aaf"> 
    Lorem ipsum dolor sit amet, consectetaur adipisicing elit, sed do eiusmod tempor 
    incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud 
    exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute 
    irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 
    pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui 
    officia deserunt mollit anim id est laborum. 
</p> 

爲標題它的工作原理,但沒有進行彙總。
我在做什麼錯?

回答

0

做這個

$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 
$pageContents = str_replace ('<!--TITLE-->', $pageTitle, $pageContents); 
$pageContents = str_replace ('<!--DESCRIPTION-->', $pageDesc, $pageContents); 
echo str_replace ('<!--KEYWORDS-->', $pageKey, $pageContents); 
+0

完美!有用!我試圖做同樣的描述,但它重複的HTML和不添加說明字符串。 echo str_replace('<! - DESCRIPTION - >',$ pageDescription,$ pageContents); – Shika93 2014-09-26 12:31:24

+0

不會複製打印出數據的'echo'行,如果您查看頁面,您實際上將擁有2套完整的數據...滾動到底部。在繼續前進之前,您需要對PHP課程做一些基本的介紹。爲了解決這個複製上面的行,並做了描述部分。 – cmorrissey 2014-09-26 12:34:29

+0

我已經重複,並添加了 」/> 是的,我有2組數據 – Shika93 2014-09-26 12:37:37

相關問題