使用 PHP 搜索 Html 标签

发布于 2025-01-01 18:44:14 字数 1056 浏览 0 评论 0原文

在我的 rootfolder/xxx/header.php 页面中有 一些文本</code>。

我想使用 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);

这是views/themes/header.php 代码:

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

theme_lib 是我在控制器代码中加载的库:

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

我想更改 测试即将发布</code>。 我该怎么做?

In my rootfolder/xxx/header.php page have <title>some text</title>.

I want to search as like this html tags using php code.

That means i want change the text inside the title tag by using php code.

How can i do this?

This is the rootfolder/xxx/header.php file code:

<!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>

In my controller code:

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

This is the views/themes/header.php code:

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

The theme_lib is a library i loaded in the controller code:

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

I want to change the <title>test</title> as <title>Launching Soon</title>.
How can i do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

帅气称霸 2025-01-08 18:44:14

您应该查看模板解析器文档,它可能会很有用。您需要做的就是这样:

<title>{title}</title>

You should review the Template Parser documentation it may prove useful. All you need to do is something like this:

<title>{title}</title>
dawn曙光 2025-01-08 18:44:14
<!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>
<!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>
英雄似剑 2025-01-08 18:44:14

您可以将标题存储在 SQL 数据库中,并使用 PHP 动态调用它们,使用 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);
 ?>

然后在页面下方的 HTML 部分中,

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

You could have the titles stored in a SQL database and call them dynamically with PHP, update the database entry with 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);
 ?>

Then in the HTML part which is further down the page,

<title><? echo $title; ?></title>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文