FW: [PHP] remove last character in a string
| From: | Jarrad Kabral | Date: | Tue, 23 Apr 2002 04:18:26 +0000 |
| Subject: | FW: [PHP] remove last character in a string | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-94111@lists.php.net to get a copy of this message | ||
its my understanding that you wish to strip the last character of the string
not return it. Putting -1 in the length parameter will just return the last
character, it wont get rid of it....
$string = "This is the string,";
$str_length = strlen($string);
if (substr($string,0,-1) == ",") {
//Strip
$formatted_str = substr($string,0,str_length-1);
} else {
//Dont strip
//
}
That should work but I didnt test it ;)
Regards
Jarrad Kabral
-----Original Message-----
From: Tyler Longren [mailto:tyler@captainjack.com]
Sent: Tuesday, 23 April 2002 1:57 PM
To: Evan Nemerson; php-general@lists.php.net
Subject: Re: [PHP] remove last character in a string
Because I'm kinda stupid. :)
tyler
----- Original Message -----
From: "Evan Nemerson" <evan@coeus-group.com>
To: "Tyler Longren" <tyler@captainjack.com>; <php-general@lists.php.net>
Sent: Monday, April 22, 2002 10:53 PM
Subject: Re: [PHP] remove last character in a string
> Why get strlen involved???
>
> $string = substr("$string", 0, -1);
>
>
>
> --
> He is richest who is content with the least, for content is the wealth of
> nature.
>
> Socrates
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php