cut off last character of strinf

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

cut off last character of strinf

Post by potato »

hellow,

im looking for a way to cut off the last character of a string.
the string is an array, en ends with a comma.
Thats what i want to cut off, the comma.
Anyone knwos how?

friendly greetz,
tom
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

use substr() funcion
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post by potato »

ok, it works. Thank you very much

here's the code for if anyone has the same problem:


Code: Select all

$pics = substr ($pics, 0, -1);
note that the -1 stands for minus 1 character at the end of the string.

So if your string is
this is my string

the result would be
this is my strin

if you want to cut 2 character, replmace the -1 with -2
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

you can also use rtrim($string, ',');
Post Reply