| | |
how do you strip tabs, extra spaces and new lines
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 4
Reputation:
Solved Threads: 0
from a string that's pulled from a mysql database? i know stripping new lines is
but what about tabs and extra spaces?
PHP Syntax (Toggle Plain Text)
$d = str_replace("\r\n","",$d);
•
•
Join Date: Feb 2006
Posts: 50
Reputation:
Solved Threads: 5
//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.
$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.
•
•
Join Date: Apr 2008
Posts: 48
Reputation:
Solved Threads: 3
php Syntax (Toggle Plain Text)
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.
![]() |
Other Threads in the PHP Forum
- Previous Thread: getting X, Y values of certain text in string on image
- Next Thread: Interactive PHP Shell (one line of PHP)
Views: 6184 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary bounce broken cakephp checkbox class cms code computing cron curl database date delete directory display domain download dynamic echo email error file files folder form forms function functions google href htaccess html image include indentedsubcategory insert integration ip java javascript joomla limit link load login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote return script search select server sessions sms soap source space speed sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube





