chopping the end of a string off
Moderator: General Moderators
-
mccommunity
- Forum Commoner
- Posts: 62
- Joined: Mon Oct 07, 2002 8:55 am
chopping the end of a string off
I have a string and it varys in size but the last part of it will always be a comma and I need to strip that off. So basically I am looking for a function that will strip the last character off a string. Thanks.
- Pointybeard
- Forum Commoner
- Posts: 71
- Joined: Wed Sep 03, 2003 7:23 pm
- Location: Brisbane, AUS
- Contact:
Well the first place you should look is the PHP documentation. :p heres the link - http://www.php.net/manual/en/
There are heaps of ways to do what you want. Functions that would interest you would be preg_replace(), strlen(), substr()...actually have a look at the list of string functions. heres the link... http://au.php.net/manual/en/ref.strings.php
Essentially all you are going to need do is either replace comma's with "", or use substr and strlen to work out how to chop off the last char.
-PB
There are heaps of ways to do what you want. Functions that would interest you would be preg_replace(), strlen(), substr()...actually have a look at the list of string functions. heres the link... http://au.php.net/manual/en/ref.strings.php
Essentially all you are going to need do is either replace comma's with "", or use substr and strlen to work out how to chop off the last char.
-PB
The easiest would probably be to use substr. Heres an example from php.net/substr:
Code: Select all
<?php
$rest = substr("abcdef", 0, -1); // returns "abcde"
?>