Wednesday, 2 October 2013

HTML linking titles and subtitles in php

HTML linking titles and subtitles in php

I am trying to make a wikipedia like thing that makes a little list with
clickable links of all the html titles <h1></h1> and <h2></h2>
So
<h1>Title</h1>
[random text about things]
<h2>subtitle</h2>
[random text]
<h2>subtitle2</h2>
<h1>Title2</h1>
[random text about things]
<h2>subtitle3</h2>
[random text]
<h2>subtitle4</h2>
would become
Title - subtitle - subtitle2 Title2 - subtitle3 - subtitle4
with all subtitles being links to that html part.
I'm thinking myself of preg_replace things, but not sure if that is the
best way. Tips?

No comments:

Post a Comment