代码之家  ›  专栏  ›  技术社区  ›  Delan Azabani

发送后使用<h2>作为标题?

php
  •  1
  • Delan Azabani  · 技术社区  · 15 年前

    目前,我的网站页面有一个半动态系统。 head.php 在内容正文之前具有所有标记, foot.php 后面的标签。使用主主题的任何页面都将包含head.php,然后编写内容,然后输出foot.php。目前,为了能够设置标题,我快速设置了一个变量 $title 加入前:

    <?php $title = 'Untitled document'; include_once '../head.php'; ?>
    <h2>Untitled document</h2>
    Content here...
    <?php include_once '../foot.php'; ?>

    所以在head.php中…

    <title><?php echo $title; ?> | Delan Azabani</title>

    然而,这似乎有些笨拙,因为大多数时候标题都是一样的,内容也是 h2 标签。有没有办法让PHP读取 H2 ,跟踪并插入,然后在末尾发送整个内容?

    2 回复  |  直到 15 年前
        1
  •  3
  •   True Soft    15 年前

    在h2标签中,添加如下标题:

     <h2><?php echo $title; ?></h2>
    
        2
  •  1
  •   Sarfraz    15 年前

    是的,您可以使用 HTML Simple DOM 阅读 <h2 .

    例子:

    $title = str_get_html('<h2></h2>');
    

    现在,您可以使用 $title 不过,你喜欢。访问他们的网站了解更多信息。

    推荐文章