我希望在 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编码解决方案,用于根据页面上的标题标签自动生成嵌套的目录?
所以我有一个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代码自动生成)