I want to strip the last character in a variable in PHP. HOw do I do this? i.e.
$var = "words";
I want to be able to strip that "s" off the end of the word. I forgot how to do this ...Thanks.
| SitePoint Sponsor |


I want to strip the last character in a variable in PHP. HOw do I do this? i.e.
$var = "words";
I want to be able to strip that "s" off the end of the word. I forgot how to do this ...Thanks.
If it's Perl you can use the function chop ;o)Originally posted by HumanClay
I want to strip the last character in a variable in PHP. HOw do I do this? i.e.
$var = "words";
I want to be able to strip that "s" off the end of the word. I forgot how to do this ...Thanks.
$var = "words";
chop($var);
Adelina.........
Web Integrator.........
I'm sorry, I didn't know what was PHP. After readind all the messages now I know!Originally posted by HumanClay
I want to strip the last character in a variable in PHP. HOw do I do this? i.e.
$var = "words";
I want to be able to strip that "s" off the end of the word. I forgot how to do this ...Thanks.
So I guess you'll receive a better answer soon!
Good luck!
Adelina.........
Web Integrator.........





Yeah, too bad I couldn't find it either, but you could use substr() for this:
substr(string,0,strlen(string)-2);
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy





I would go with what Son said except shouldn't be
$var = substr($var,0,strlen($var)-1);
Please don't PM me with questions.
Use the forums, that is what they are here for.





Oh yeah, Freddy! I thought the substr has syntax like this: substr(str,startIndex,endIndex)
But it is: substr(str,startIndex,lengthToGrasp);
So yes, it should be what Freddy gave ya!![]()
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy


Thanks. It worked.![]()
Alternatively, using regular expressions:
$var = ereg_replace("^(.*).$","\\1",$var);
Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference





Just a note: with reg. expression, the cost is performance if you use it many times
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy
Bookmarks