How to list/find html tags in text

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


What I try to do is to search a text for html tags.

Why. Because I want to use nl2br on the text, but since this command add  
br instead of all /n it is not a nice thing to add t.x. a html list inside  
the text. Of course it is possible to add the list and remove all space  
between li tags, but this is not so readable to the writer.

What I try to do is also to add nl only in the plain text and inside li  
and td tags. So in the li case I have to find <ul> and </ul> and <table  
Quoted text here. Click to load it

I did find a nice regular expression at
function ereg_MatchedHTMLTags($tagname) {
"^(.*)(<[ \n\r\t]*$tagname(>|[^>]*>))(.*)(<[ \n\r\t]*/[
wich result in this.
// The following values will be held in $Matches
//(marked values are unintended byproducts of the expression)
//          *[0] - the entire string ($Source).
//            [1] - everything before the opening tag
//            [2] - the opening tag, including all contents (i.e.  
everything between < and >)
//          *[3] - the opening tag from end of the tag name,
//                      e.g. '<body bgcolor="#000000">' gives '  
//            [4] - the tag contents (everything between the opening and  
closing tag)
//            [5] - the complete closing tag.
//          *[6] - the closing tag from the end of the tag name
//                      e.g. '</body invalid text>' gives ' invalid text>'
//            [7] - everything after the closing tag.

Nice. But it if there is two similar html tags, it returns the last one,  
not the first.

So someone that can set me on the track of how to accomplish my goals?

Regards, Sindre

Re: How to list/find html tags in text

have you tryed to put verything in string sertch and abort when the first  
one found, return everyting before abort and research the rest of string?  
hope you understand were Iam doing with that

Quoted text here. Click to load it
Quoted text here. Click to load it


Thanx in advance
BTW. I know my english is not best in the word, so please stop bugging me  
about my spelling. And yes Iam sorry you don't understand what I mean, but  
there is no point to yell at me. Have a nice day.

Site Timeline