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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.