[PHP] How to remove only the last character?

2003-02-08 Thread Douglas Douglas
Good day.

Is there any PHP function that removes only the last
character of a string and returns the new string?

I'm looking in the manual and I can't find anything.

Until now I'm doing this:

$var=substr($var,0,strlen($var)-1)

Is this the most efficient way?

Thanks.

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] How to remove only the last character?

2003-02-08 Thread Ian Packer
Hiya,

Try this, *probably* more efficient but I don't know for sure.

?

$string = 'testing 1 2 3 testing';

echo $string . \n;

$string[strlen($string)-1] = \0;

echo $string . \n;

?

Regards,

Ian Packer


- Original Message - 
From: Douglas Douglas [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, February 08, 2003 1:21 PM
Subject: [PHP] How to remove only the last character?


 Good day.
 
 Is there any PHP function that removes only the last
 character of a string and returns the new string?
 
 I'm looking in the manual and I can't find anything.
 
 Until now I'm doing this:
 
 $var=substr($var,0,strlen($var)-1)
 
 Is this the most efficient way?
 
 Thanks.
 
 __
 Do you Yahoo!?
 Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
 http://mailplus.yahoo.com
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] How to remove only the last character?

2003-02-08 Thread Douglas Douglas
I want to thank you Ian, Zydox and Nicos.

After Zydox response I checked the manual again and
read this part in the substr function:

If length is given and is negative, then that many
characters will be omitted from the end of string
(after the start position has been calculated when a
start is negative)

Sorry to bother you guys, and thanks again.

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] How to remove only the last character?

2003-02-08 Thread Kevin Waterson
This one time, at band camp,
Douglas Douglas [EMAIL PROTECTED] wrote:

 Good day.
 
 Is there any PHP function that removes only the last
 character of a string and returns the new string?


$new = substr($string, 0, -1);

Kevin
-- 
 __  
(_ \ 
 _) )            
|  /  / _  ) / _  | / ___) / _  )
| |  ( (/ / ( ( | |( (___ ( (/ / 
|_|   \) \_||_| \) \)
Kevin Waterson
Port Macquarie, Australia

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php