RE: [PHP] removing last chr in string

From: Date: Fri, 27 Oct 2000 20:25:37 +0000
Subject: RE: [PHP] removing last chr in string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-22375@lists.php.net to get a copy of this message
At 6:32 PM -0600 10/26/00, Jason Cox wrote:
Try: $string = substr(0,strrpos($string,',')-1);
I think you _really_ meant: $string = substr($string, 0, strrpos($string,',')-1); Or: $string = ereg_replace(",\$", '', $string); If you _always_ want to remove the last character, you can simply $string = substr($string, 0, -1); see: http://www.php.net/manual/function.ereg-replace.php http://www.php.net/manual/function.substr.php I'm pretty sure you can use preg_replace() here as well, for a slight speedup: $string = preg_replace(",\$", '', $string); See: http://www.php.net/manual/function.preg-replace.php -steve
-----Original Message----- From: Rebecca [mailto:rebecca@digitalpulp.com] Sent: Thursday, October 26, 2000 3:35 PM To: php-general@lists.php.net Subject: [PHP] removing last chr in string is there a quick and easy way to remove the last character in a string if it is not a whitespace, newline, tab, etc? the last character is always a comma - i want to remove the comma. _______________________________________________________ Site Design, Hosting, and E-Commerce at www.webpipe.net
+--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg                           University of California, Davis |
| sbedberg@ucdavis.edu                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+

« previous php.general (#22375) next »