Jump to content

[SOLVED] remove trailing slash


heavyEddie

Recommended Posts

OK, I can't see any reason that this line of code isn't working.  It is intended to remove a trailing slash if it exists... but it doesn't.  It seems to work for displaying the string without the trailing slash, but not defining the variable.

 

I have a feeling this is going to be a "DUH" moment.

 

Doesn't work...

if(substr($url, -1) == "/") $url = substr($url, 0, -1);

 

However, this will display what I'm looking for

if(substr($url, -1) == "/") echo substr($url, 0, -1);

Link to comment
https://forums.phpfreaks.com/topic/75914-solved-remove-trailing-slash/
Share on other sites

That would certainly do it as well, but I found the answer...  In my code I was calling a different variable than what this code was using.

 

Man... I new it would be a stupid answer.

 

If nothing else, folks can now see two methods for removing a trailing slash.  I think I read someplace the using substr was faster than preg_replace.  Not sure if that is accurate though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.