相关疑难解决方法(0)

在 php 中创建目录

我希望在 php 中创建一个非常简单、非常基本的嵌套目录,它可以获取所有 h1-6 并适当缩进内容。这意味着如果我有类似的东西:

<h1>content</h1>
<h2>more content</h2>
Run Code Online (Sandbox Code Playgroud)

我应该得到:

content
    more content.
Run Code Online (Sandbox Code Playgroud)

我知道将由 css 创建缩进,这很好,但是如何创建一个包含指向页面内容的工作链接的目录?

显然很难理解我的要求......

我要求一个读取 html 文档并提取所有 h1-6 并制作目录的函数。

php tableofcontents

3
推荐指数
1
解决办法
6671
查看次数

根据标题标记自动生成嵌套的目录

哪位狡猾的程序员可以向我展示一个优雅的PHP编码解决方案,用于根据页面上的标题标签自动生成嵌套的目录?

所以我有一个html文件:

<h1> Animals </h1>

Some content goes here.
Some content goes here.

<h2> Mammals </h2>

Some content goes here.
Some content goes here.

<h3> Terrestrial Mammals </h3>
Some content goes here.
Some content goes here.

<h3> Marine Mammals </h3>
Some content goes here.
Some content goes here.

<h4> Whales </h4>
Some content goes here.
Some content goes here.
Run Code Online (Sandbox Code Playgroud)

更具体地说,我想要一个链接的目录,其形式是在同一页面上的标题链接的嵌套列表:

目录(由PHP代码自动生成)

  1. 动物
    1. 哺乳动物
      1. Terrestrial_Mammals
      2. Marine_Mammals
        1. 鲸鱼

php dynamically-generated

2
推荐指数
4
解决办法
7091
查看次数