how do you strip tabs, extra spaces and new lines

Reply

Join Date: Apr 2008
Posts: 4
Reputation: Geonith is an unknown quantity at this point 
Solved Threads: 0
Geonith Geonith is offline Offline
Newbie Poster

how do you strip tabs, extra spaces and new lines

 
0
  #1
Apr 14th, 2008
from a string that's pulled from a mysql database? i know stripping new lines is
  1. $d = str_replace("\r\n","",$d);
but what about tabs and extra spaces?
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 50
Reputation: ultra vires is an unknown quantity at this point 
Solved Threads: 5
ultra vires ultra vires is offline Offline
Junior Poster in Training

Re: how do you strip tabs, extra spaces and new lines

 
0
  #2
Apr 15th, 2008
//Newline and tab space to single space

$from_mysql = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $from_mysql);


// Multiple spaces to single space ( using regular expression)

$from_mysql = ereg_replace(" {2,}", ' ',$from_mysql);

// Replaces 2 or more spaces with a single space, {2,} indicates that you are looking for 2 or more than 2 spaces in a string.
Last edited by ultra vires; Apr 15th, 2008 at 5:14 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 48
Reputation: helraizer is an unknown quantity at this point 
Solved Threads: 3
helraizer helraizer is offline Offline
Light Poster

Re: how do you strip tabs, extra spaces and new lines

 
0
  #3
Apr 17th, 2008
  1. trim($d);

This function returns a string with whitespace stripped from the beginning and end of str . Without the second parameter, trim() will strip these characters:

* " " (ASCII 32 (0x20)), an ordinary space.
* "\t" (ASCII 9 (0x09)), a tab.
* "\n" (ASCII 10 (0x0A)), a new line (line feed).
* "\r" (ASCII 13 (0x0D)), a carriage return.
* "\0" (ASCII 0 (0x00)), the NUL-byte.
* "\x0B" (ASCII 11 (0x0B)), a vertical tab.
Sam
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 6184 | Replies: 2
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC