2012-02-02 91 views
0

在我的rootfolder/xxx/header.php頁面中有<title>some text</title>使用PHP搜索HTML標籤

我想使用php代碼來搜索像這個html標籤。

這意味着我想通過使用php代碼來改變標題標籤內的文本。

我該怎麼做?

這是rootfolder/XXX/header.php文件代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>test</title> 
</head> 

在我的控制器代碼:

$data['title'] = "Launching Soon"; 
    $this->load->view('themes/header',$data); 

這是意見/主題/的header.php代碼:

<?php 
    $this->theme_lib->get_header("xxx"); 
?> 

theme_lib是我裝入控制器代碼的庫:

public function get_header($name = ""){ 
    include($name.'/header.php'); 
    } 

我想將<title>test</title>更改爲<title>Launching Soon</title>。 我該怎麼做?

回答

1

您應該查看它可能證明有用的Template Parser文檔。所有你需要做的就是這樣的:

<title>{title}</title> 
-1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title><?php echo $title;?></title> 
</head> 
+0

更好的方法是使用CodeIgniter模板框架。有關更多信息,請參見[文檔](http://codeigniter.com/user_guide/libraries/parser.html)。 – 2012-02-02 05:32:09

+0

他使用codeigniter,你沒有很好的閱讀 – 2012-02-02 05:40:49

+0

是的,我知道他使用CodeIgniter。您不需要使用'<?php echo $ title;?>'使用此'{title}'代替。 – 2012-02-02 05:49:36

-1

你可以有存儲在SQL數據庫中的標題,並用PHP動態調用它們,更新HTML部分用PHP數據庫條目

<?php 
$con = mysql_connect("localhost","root","password"); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 

mysql_select_db("mysite1", $con); 

$result = mysql_query("SELECT * FROM headers"); 

while($row = mysql_fetch_array($result)) 
    { 
$title = $row['title'] 
    } 

mysql_close($con); 
?> 

然後進一步下跌的頁面,

<title><? echo $title; ?></title>