GeekyCorner
09 Oct remove last character from string in php Posted by Matt | 32 Comments
I tried trim but did not work. Thnx

32 Replies to "remove last character from string in php"

Sasho Valkanov October 9, 2006 at 11:25 am | Reply

+43

if you have a string $string try using

substr_replace($string ,"",-1);

it will remove tha last character from $string.
Sreeram August 11, 2012 at 7:05 pm

+7

Thanks!
me December 24, 2007 at 6:27 pm | Reply

+9

This doesn't even work..
Yann November 16, 2012 at 6:15 pm

+22

This doesn't EVEN work because you need to do this:
$string = substr_replace($string ,"",-1);

NOT JUST

substr_replace($string ,"",-1);

the dude March 3, 2008 at 10:01 pm | Reply

+40

Veselin, nice response. Jon, why put Matt down, he's clearly learning. I pray that you don't pollute the world with any offspring.
Hector May 23, 2008 at 7:53 pm | Reply

+7

Veselin, nice response. the dude, I pray that any of your offspring aren't as nosey and judgemental as you.
MyZelf June 7, 2008 at 2:45 pm | Reply

+3

Hey, sorry, gotta make the remark: you don't have to guess words anymore!! ...that's what color syntaxing text editors are about :)

Sangili(India) July 4, 2008 at 9:19 am | Reply

0

I got an exact answer dude, thanks.
aravind July 15, 2008 at 9:48 pm | Reply

+2

thanks. its really working well
Abarna July 15, 2008 at 9:50 pm | Reply

+2

Thanks
nex August 14, 2008 at 11:19 pm | Reply

+15

substr($string,0,-1);

removes last char..
N October 29, 2008 at 10:19 pm | Reply

+5

Actually, trim can work. Specifically, rtrim.

echo rtrim('remove the letter a', 'a');


Please be polite and helpful and do not spam or offend others. We promise you will be treated the same way.

Log in your free account or if you still haven't joined you can create your free account now.

Posting tip:
if you use code in your comments please put it in these tags [php], [sql], [css], [js]
PHP code example: [php] echo date("Y-m-d"); [/php]

Thank you,
~ PHPJabbers team ~