strip newlines in TD cell ?

  • Thread starter Richard A. DeVenezia
  • Start date
R

Richard A. DeVenezia

Can't figure this one out...

How can I strip all the newlines of stuff between <TD and </TD> ?

I read in and join some HTML
<TABLE><TR><TD>1
2
3
</TD>
<TR><TD>A
B
C</TD></TR></TABLE>

that I want process as

<TABLE><TR><TD>1 2 3</TD>
<TR><TD>A B C</TD></TR></TABLE>

Thanks.
 
J

Jürgen Exner

Richard said:
Can't figure this one out...

How can I strip all the newlines of stuff between <TD and </TD> ?

I read in and join some HTML

Maybe by using an HTML parser to parse HTML?
Contrary to popular believe parsing HTML correctly is close to rocket
science and nobody with a sane mind would attempt to do that using REs
alone.

For further details please see the FAQ. 'perldoc -q HTML':
"How do I remove HTML from a string?"

jue
 
T

Tad McClellan

Richard A. DeVenezia said:
How can I strip all the newlines of stuff between <TD and </TD> ?


Use a module that can properly parse HTML.

I read in and join some HTML
<TABLE><TR><TD>1
2
3
</TD>
<TR><TD>A
B
C</TD></TR></TABLE>

that I want process as

<TABLE><TR><TD>1 2 3</TD>
<TR><TD>A B C</TD></TR></TABLE>


Then why did you say you wanted to _strip_ newlines?

If you stripped newlines, you'd end up with:

<TABLE><TR><TD>123</TD>
<TR><TD>ABC</TD></TR></TABLE>

It appears that what you actually want is to replace newlines
with spaces...


s#(<TD>.*?</TD>)# $a=$1; $a =~ tr/\n/ /; $a #gse;


But that does not produce output like your example either.

I'll leave it to you to make it do whatever it is that you want done...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top