Hi,
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[color=blue]
><tr> </tr> </table>[/color]
I did find a nice regular expression at php.net:
function ereg_MatchedHTM LTags($tagname) {
return
"^(.*)(<[ \\n\\r\\t]*$tagname(>|[^>]*>))(.*)(<[ \\n\\r\\t]*/[ \\n\\r\\t]*$tagname(>|[^>]*>))(.*)$";
}
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="#00000 0">' gives '
bgcolor="#00000 0">'
// [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
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[color=blue]
><tr> </tr> </table>[/color]
I did find a nice regular expression at php.net:
function ereg_MatchedHTM LTags($tagname) {
return
"^(.*)(<[ \\n\\r\\t]*$tagname(>|[^>]*>))(.*)(<[ \\n\\r\\t]*/[ \\n\\r\\t]*$tagname(>|[^>]*>))(.*)$";
}
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="#00000 0">' gives '
bgcolor="#00000 0">'
// [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
Comment