2014-09-26 19 views
-1

키워드 및 설명 메타 태그가 동적으로 작성되기를 원합니다. 나는이 thead을 보았지만 메타 태그에 대해서도 똑같이 할 수는 없다.
여기 내 코드입니다 : 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 ('', $ pageDescription, $ pageContents); – Shika93

+0

당신의 데이터를 출력하는'echo' 라인을 복제하지 마십시오. 실제로 페이지의 두 세트를 가지고있을 것입니다. 아래로 스크롤하십시오. 앞으로 나아 가기 전에 PHP 레슨에 대한 기본적인 소개를해야합니다. 이것을 해결하려면 위의 행을 복제하고 설명 부분을 작성하십시오. – cmorrissey

+0

나는 이미 복제했으며 추가 한 내용은 입니다. 예 2 세트의 데이터가 있습니다 – Shika93