Possible Duplicate:
remove last character from string
I want to delete the last character in the text..
For example
My string: example text
Second : example tex
How?
Use substr
$text = 'Example Text';
$text = substr($text, 0, -1)
substr takes three arguments, the original text, start and length, it return the substring from the original text starting at start with the given length. If length is negative, that number of characters will be excluded from the string, that's why whe are using the value -1, to exclude the last char from the string.
Use substr, which gets a substring of the original string:
$str = 'example text';
$newStr = substr($str, 0, -1); // "example text"
0 means "start at the beginning", -1 means "go until one character before the end".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With