Possible Duplicate:
How to parse and process HTML with PHP?
I am looking for a php function that decreases html hx (h1, h2, h3, …, h6) tags by one.
- h1 becomes h2
- h2 becomes h3 and so on
- …
- h6 gets replaced by ‘ ‘
do you know such a function?
This is how I started stripping the h6 tags:
$string = preg_replace('#<(?:/)?\s*h6\s*>#', ' ', $string);
Here’s one for
DOM, which iterates trough all mappings and then replace tags or copies children.You may also do some
xPathoptimalizations like using//*or//h3|//h2and checkingDOMElement::tagName, but I wanted this to be straight forward.Edit: Solution that goes trough nodes only once and doesn’t care about order:
And the last optimalization I can think about is using: