PHP gets all private HTML tags in a string

How can I get all closed tags in a given string, preferably in the order in which they should be closed?

Note. Please note that there are no errors in HTML and that it was simply disabled after the X characters. No, this is not the case with bad html or overlapping tags, etc. There will also be no end

Example: <p><span>Lorem</span><b>ipsum --- return ---> </b></p>
-OR-
<ul><li>1</li><li>2 --- return ---> </li></ul>

So, if a string is concatenated with the output of a function, it will again create valid HTML.

I'm not sure if RegExp will do the trick here, basically I want to get something between <and> that does not have a matching </> closing tag.

Thanks.

0
source share
1 answer

This is not an easy task. You can watch Tidy :

Tidy is a must-have Tidy HTML cleanup and repair utility that allows you to not only clean and manipulate HTML documents, but also traverse the document tree.

http://php.net/manual/en/book.tidy.php

+3
source

Source: https://habr.com/ru/post/1236743/


All Articles