heavyEddie Posted November 3, 2007 Share Posted November 3, 2007 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 More sharing options...
rajivgonsalves Posted November 3, 2007 Share Posted November 3, 2007 try $url = preg_replace("/\/$/","",$url); Link to comment https://forums.phpfreaks.com/topic/75914-solved-remove-trailing-slash/#findComment-384220 Share on other sites More sharing options...
heavyEddie Posted November 3, 2007 Author Share Posted November 3, 2007 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 https://forums.phpfreaks.com/topic/75914-solved-remove-trailing-slash/#findComment-384223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.