Re: Re: Re: [PHP] CR and LF Filtering
| From: | Chris Carbaugh | Date: | Mon, 18 Dec 2000 01:58:11 +0000 |
| Subject: | Re: Re: Re: [PHP] CR and LF Filtering | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-30809@lists.php.net to get a copy of this message | ||
At a quick glance at your function, with no testing, it seems it would
turn this:
"This is old \r This is new"
into this:
"This is old This is new"
When it should be turned into this:
"This is new"
Or did I miss somthing?
Chris
On Sun, 17 Dec 2000, Philip Olson wrote:
> Date: Sun, 17 Dec 2000 21:28:19 +0000 (GMT)
> To: Chris Carbaugh <cjtech2000@yahoo.com>
> From: Philip Olson <philip@theprojects.org>
> Subject: Re: Re: [PHP] CR and LF Filtering
>
> How about :
>
> function stripSpace($string,$suffix=' ')
> {
> $pieces = split('[[:space:]]+',$string);
>
> foreach ($pieces as $piece) {
>
> $new_string .= $piece . $suffix;
> }
>
> Return $new_string;
> }
>
> This should do what you want, right? Where $suffix is what goes
> between
> every word (' ' being a space). The above shoulds strip newlines,
> carriage returns and tabs (all spaces).
>
> Regards,
>
> Philip
>
>
> --.sig
> [ Want to write Good code? First, write Bad code. ]
>
> On Sun, 17 Dec 2000, Chris Carbaugh wrote:
>
> >
> > This function takes as argument a single string, the sting most
> likly
> > being a line from a file. It returns the string formatted as
> though it
> > was printed on the console or through a carriage (dot matrix)
> printer.
> >
> > ------------------------------------------------------
> > // removes all ascii charactor 13 (carriage returns)
> > // compresses the content to emulate the output a carriage printer
> > would give
> > function compressCR ($str){
> > $pos = strpos($str, 13); // find position
> of
> > first CR
> > $i = 0;
> > while (!($pos === false)) { // while a CR
> exists
> > if ($pos == 0){ // CR = first
> char of
> > string
> > $str = substr($str, ($pos + 1)); // save all after
> CR
> > } else {
> > $newStr[$i] = substr($str, 0, $pos); // save all before
> CR
> > $str = substr($str, ($pos + 1)); // save from char
> > ($pos+4) to end
> > }
> > $i++;
> > $pos = strpos($str, 13); // find postition
> of
> > next CR
> > }
> > $newStr[$i] = $str;
> >
> > $j = 1;
> > $str = chop($newStr[0]); // remove
> trailling
> > spaces
> > while ($newStr[$j]){ // while array
> > element exists
> > $str .= chop(substr($newStr[$j], strlen($str))); // add two
> string
> > together
> > // first
> removing
> > the number of charactors
> > // in the
> first
> > string from the beginning
> > // of the
> second
> > string
> > $j++;
> > }
> > return $str;
> > }
> > ------------------------------------------------------
> >
> > Hope you find this useful. I would like to hear any comments you
> have
> > on it.
> >
> > Chris
> >
> > On Sat, 16 Dec 2000, Don Smith wrote:
> > > Date: Sat, 16 Dec 2000 17:15:07 -0600
> > > To: <cjtech2000@yahoo.com>
> > > From: Don Smith <don@newsvideo.com>
> > > Subject: Re: [PHP] CR and LF Filtering
> > >
> > > I know exactly to what you refer. Yes, if it's not a lot of
> trouble,
> > > I'd
> > > like to see that function. Thank you very much.
> > >
> > > Don Smith
> > > NewsVideo.com
> > >
> > > > From: Chris Carbaugh <cjtech2000@yahoo.com>
> > > > Reply-To: cjtech2000@yahoo.com
> > > > Date: Sat, 16 Dec 2000 16:09:04 EST
> > > > onald Smith <don@newsvideo.com>, <php-general@lists.php.net>
> > > > Subject: Re: [PHP] CR and LF Filtering
> > > >
> > > >
> > > > I think someone has already replied with str_replace("\r",
> > > $string),
> > > > BUT:
> > > >
> > > > You need to watch those carriage returns. If you have some
> text
> > > after
> > > > a <cr>, it may have been intended to overwrite the text before
> the
> > > > <cr>. Many command line apps do htis sort of thing in order to
> > > have a
> > > > progress line, a single line that is updated every half second
> or
> > > so.
> > > >
> > > > I wipped up a function to handle this sort of thing a while
> ago.
> > > If
> > > > you like, I can dig it up for you.
> > > >
> > > > Chris
> > > >
> > > > On Fri, 15 Dec 2000, Donald Smith wrote:
> > > >> Date: Fri, 15 Dec 2000 07:50:07 -0600
> > > >> To: <php-general@lists.php.net>
> > > >> From: Donald Smith <don@newsvideo.com>
> > > >> Subject: [PHP] CR and LF Filtering
> > > >>
> > > >> I need to filter carriage returns and line feeds from a
> string.
> > > I've
> > > >> searched the string functions in the PHP Manual and nothing
> seems
> > > to
> > > >> do the
> > > >> job. I'm sure I'm missing something, though, and am asking
> this
> > > list
> > > >> for
> > > >> assistance.
> > > >>
> > > >> Thanks
> > > >> Don Smith
> > > >> mailto:don@newsvideo.com
> > > >>
> > > >>
> > > >> --
> > > >> PHP General Mailing List (http://www.php.net/)
> > > >> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > > >> For additional commands, e-mail:
> php-general-help@lists.php.net
> > > >> To contact the list administrators, e-mail:
> > > >> php-list-admin@lists.php.net
> > > >>
> > > > --
> > > > "I love my country. I fear my government." - Bumper Sticker
> > > >
> > > >
> > >
> > --
> > "I think your slogan 'Liberty or Death' is splendid, and whichever
> one
> > you decide on will be all right with me." - Alexander Woollcott
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
> >
>
>
--
"Every day I give you a piece of my death" - Marilyn Manson