Page 1 of 1
trim does not take off the line breaks
Posted: Wed Aug 09, 2006 9:47 am
by raghavan20
trim function does not take off the line breaks...what is the function or any available way to strip off all the spaces and line breaks from a string stored in the DB using Mysql.
Posted: Wed Aug 09, 2006 9:48 am
by raghavan20
is there is any preg_replace equivalent function in mysql to remove off unwanted characters?
Re: trim does not take off the line breaks
Posted: Wed Aug 09, 2006 9:56 am
by JayBird
raghavan20 wrote:trim function does not take off the line breaks...what is the function or any available way to strip off all the spaces and line breaks from a string stored in the DB using Mysql.
Yes it does!?
Posted: Wed Aug 09, 2006 10:04 am
by raghavan20
i hope you have read that i have mentioned in mysql.
I am working purely with mysql procedures.
ex:
Code: Select all
select concat(trim( ' sdfsf
'), '##');
+---------------------------------------------------------------+
| concat(trim( ' sdfsf
'), '##') |
+---------------------------------------------------------------+
| sdfsf
## |
+---------------------------------------------------------------+
1 row in set
Posted: Wed Aug 09, 2006 10:09 am
by JayBird
ah, i see...back to the coffee and biscuits


Posted: Wed Aug 09, 2006 10:25 am
by raghavan20
do you think we can use any mysql regex to remove the line breaks?
Posted: Wed Aug 09, 2006 10:46 am
by infolock
is there any reason why you can't select the field and just trim it with php?
Posted: Wed Aug 09, 2006 10:57 am
by infolock
try this...
Code: Select all
SELECT concat(trim(REPLACE(' sdfsf
, '\\n', '')), '##');
Posted: Wed Aug 09, 2006 11:13 am
by raghavan20
i changed it a bit...looks like working...thanks for your idea..
Code: Select all
SELECT concat(trim(REPLACE(' sdfsf
', '\r\n', '')), '##');
+----------------------------------------------------------------------------------+
| concat(trim(REPLACE(' sdfsf
', '\r\n', '')), '##') |
+----------------------------------------------------------------------------------+
| sdfsf## |
+----------------------------------------------------------------------------------+
1 row in set
Posted: Wed Aug 09, 2006 11:26 am
by infolock
Np. Wasn't sure if you would have to escape the \n with \, so i just put it in there just in case (hadn't tested it..)
Glad to see it's working though. have fun.