[ic] Cleaning carriage returns etc.

Ryan Hertz rhertz@baits.com
Thu, 12 Apr 2001 16:51:36 -0700


> > Hi list,
> >
> > I bumped in problems with a field that I clean from tabs, carriage returns
> > etc. The formatting afterwards is not really what I want when I
> > display the
> > value somewhere...
> >
> > Can someone help me with some tips in what way <textarea> fields should be
> > collected and stored (eg. tab replaced with 3 spaces etc.), in
> > other words:
> > what is safe to store in a tab-delimited file and what is not, and how
> > should these characters be replaced/removed.

The only TWO things a Tab-delimited file can't have stored as a record is a 
tab and a return (newline). :-)  Specifically, a tab indicates a new field, 
and a newline indicates the end of the row.

These can be easily removed with a little Perl regexp such as s/\t// or 
s/\n// , but I'm dangerous with Perl regexps, we'll let someone else post 
better code, or you can do some studying on your own.  Interchange may have 
filters that handle this automatically... Check the docs.

I don't believe it is possible for a browser to enter a tab into any form 
field... but that isn't a good reason not to trap it.  :-)

>I forgot to ask also that how should I handle the displaying for this value
>in eg. a table cell after it is pulled out from the database...


If you want to "Reconstruct" the formatting after storing it in a 
tab-delimited file, perhaps the regexp should replace the newlines with a 
difficult-to-guess word or string that can be undone later.  That is, 
replace the newline with "!!!newline!!!" or such, so that you can later 
replace that with the \n return.

Don't forget that in HTML, returns are ignored.  So either display the 
results within <PRE> or (as previous) replace the newlines with <BR>


Ryan Hertz                                              tel  800-645-BAIT
Webmaster                                               fax  520-645-2588
Advertising Director                                 http://www.baits.com
Gary Yamamoto Custom Baits, Inc.                  mailto:rhertz@baits.com