Web Hosting Talk







View Full Version : deleting the last element of a string


bumpy
11-15-2002, 08:38 AM
Hello there!

my question: How do I delete the last element of a string??

i.e.: an url ends like this: .../index.php/
and now I need to trim the last slash otherwise relatively linked images won't load anymore

This problem with the last slash occures when I link to a file that starts a session and gets a variable. then it returns to the page it was loaded from (via $HTTP_REFERER), and at that point it adds a slash to the end...and another one if I reopen it, to change registered variable...and so on.

So is there a possibility to cut this last slash of every time it adds it even without knowing the actual length of - in this case - the url ??:confused:

jtrovato
11-15-2002, 01:34 PM
$variable = substr ($variable,0, (strlen($variable)-1) )


would this work?

MarkIL
11-16-2002, 04:18 PM
A shorter version would be


$t = 'abcd';
$t[strlen($t)-1] = '';

jtrovato
11-17-2002, 12:00 PM
that's a good one didn't think of that...

John