Re: remove last comma in string

From: Date: Fri, 09 Jun 2006 22:17:01 +0000
Subject: Re: remove last comma in string
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-237717@lists.php.net to get a copy of this message
weetat wrote:
I have a sql statement below :
    UPDATE tbl_chassis_temp SET  country = 'Singapore',  city 'SINGAPORE',  building = 'Tampines Central 6',  other = 'Level 03-40',
I need to remove the last comma from sql text above. I have tried using substr and rtrim , without any success ?
At 06:10 PM 6/8/2006, Chris wrote:
How about: $query = substr(trim($query), 0, -1);
This feels like a hack to me -- it acts blindly, assuming that just the comma and no extra spaces are at the end of the string. Better I think to intelligently remove just those characters one wishes to remove. At 03:00 PM 6/9/2006, Richard Lynch wrote:
rtrim() won't work, as ',' is not whitespace.
Richard, you're wrong -- read the manual. All three functions trim(), ltrim(), and rtrim() allow you to append an optional list of characters to be trimmed: http://php.net/trim http://php.net/ltrim http://php.net/rtrim Regards, Paul

« previous php.general (#237717) next »