J
jwcarlton
I'm working on an area where the visitor submits content via
contenteditable, so the submission comes through in Word-style HTML
(meaning, it's somewhat of a mess, and completely dependent on the
users browser).
I'm trying to remove opening and closing <br> tags. The problem I'm
having is when those tags come after a <font, <div, or <span, or
before a closing </font>, </div>, or </span>; eg:
<div class=whatever><span class=whatever><font
class=whatever><br><br><br>Hello, World!<br><br></font></span></div>
It's worth noting that <div>...</div> may or may not be there,
<span>...</span> may or may not be there, <font>...</font> may or may
not be there, they could be transposed (ie, <font> before <span>), and
the <br> tags can be from 0 to 3.
Here's where I am so far:
$text =~ s/^(<div(.*?)>)(<br>)+/$1/gi;
$text =~ s/^(<span(.*?)>)(<br>)+/$1/gi;
$text =~ s/^(<font(.*?)>)(<br>)+/$1/gi;
$text =~ s/(<br>)+(<\/div>)$/$2/gi;
$text =~ s/(<br>)+(<\/span>)$/$2/gi;
$text =~ s/(<br>)+(<\/font>)$/$2/gi;
I have 3 questions on this:
1. First off, does the code above look technically correct to you?
Meaning, would it work if we assume that the tags are always div,
followed by span, followed by font?
2. Is there a way to get these on 1 line?
3. How can I code it to work regardless of which tag comes first?
TIA,
Jason
contenteditable, so the submission comes through in Word-style HTML
(meaning, it's somewhat of a mess, and completely dependent on the
users browser).
I'm trying to remove opening and closing <br> tags. The problem I'm
having is when those tags come after a <font, <div, or <span, or
before a closing </font>, </div>, or </span>; eg:
<div class=whatever><span class=whatever><font
class=whatever><br><br><br>Hello, World!<br><br></font></span></div>
It's worth noting that <div>...</div> may or may not be there,
<span>...</span> may or may not be there, <font>...</font> may or may
not be there, they could be transposed (ie, <font> before <span>), and
the <br> tags can be from 0 to 3.
Here's where I am so far:
$text =~ s/^(<div(.*?)>)(<br>)+/$1/gi;
$text =~ s/^(<span(.*?)>)(<br>)+/$1/gi;
$text =~ s/^(<font(.*?)>)(<br>)+/$1/gi;
$text =~ s/(<br>)+(<\/div>)$/$2/gi;
$text =~ s/(<br>)+(<\/span>)$/$2/gi;
$text =~ s/(<br>)+(<\/font>)$/$2/gi;
I have 3 questions on this:
1. First off, does the code above look technically correct to you?
Meaning, would it work if we assume that the tags are always div,
followed by span, followed by font?
2. Is there a way to get these on 1 line?
3. How can I code it to work regardless of which tag comes first?
TIA,
Jason