|
Posted by severin on 01/16/07 12:43
Thanks J.O. Aho for your answer,
My question is bad written.
Actually, i wonder about the difference between
"trim" : the php function
and "trim" the mysql function.
$mystr = trim( $mystr ); skip all white caracters (space, carriage
return,tab...)
but the sql request:
$sql = "update mybase set name = trim( name ) "
//(here trim is the mysql function)
mysql_query( $sql )
makes the field 'name' of 'mybase' whithout spaces but keeps carriage
return,tab... The mysql trim function only skips spaces.
to skip carriage in mysql i found:
$sql = "update mybase set name = replace( "\n","", name )";
but tab,line feed,NULL and other white caracters are still here...
and i have to do:
$sql = "update mybase set name = replace( "(tab?)","", name )";
$sql = "update mybase set name = replace( "(linefeed?)","", name )";
$sql = "update mybase set name = replace( " ","", name )";
to update my name filed whithout white caracteres.
I'm searching a mysql syntax to do all thouses updates in one only
query. Probably using regexp but i don't know how??
$sql = "update mybase set name = replace( "\n| |\r|\t","", name )";
J.O. Aho wrote:
> severin wrote:
>
>> Hi all,
>>
>> I try "update mybase set name = trim(name)"
>>
>> to skip spaces.
>>
>> But 'charriot return'
>> (\13\10) are always here.
>>
>> How can i remove ( or select ) all invisible characteres??
>
>
> The placement of the "whitespaces" are important when using trim(), it
> takes only those that are in the beginning or/and end of the string.
>
> so if you have a string like, "hello\n\rThis is my string", trim will
> give you the string "hello\n\rThis is my string" as the charterers in
> question are in the middle of the string.
>
> http://www.php.net/manual/en/function.trim.php
>
>
> If you want to trim characters in the middle of a string, you may want
> to use something like eregi_replace().
>
> $newstring=eregi_replace("\n\r",'',"hello\n\rThis is my string");
> // $newstring="helloThis is my string"
>
> http://www.php.net/manual/en/function.eregi-replace.php
>
>
Navigation:
[Reply to this message]
|