Re: removing chars from string

From: Date: Mon, 27 Jun 2005 15:44:13 +0000
Subject: Re: removing chars from string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-217690@lists.php.net to get a copy of this message
Paul Nowosielski <paul@celebrityaccess.com> wrote: > If a have a string thats 11 characters long how can I strip off the last > two characters? Jay Blanchard <jay.blanchard@niicommunications.com> wrote: > $newString = substr($oldString, 0, 8); > echo $newString; substr's third argument is length, not position. It also accepts negative values which makes it go from the end, allowing you to do absolute lengths or relative. To make a string no more than 9 characters: substr($string, 0, 9); To always remove the last two characters of a string: substr($string, 0, -2); http://php.net/substr

« previous php.general (#217690) next »