0

I'm trying to make a url safe for later use. So I want to strip the slashes from the end of the url string.

Actually I'm doing:

function getUrl() {
    $url = "url/with/ending/slashes///";
    if(..someConditions..) {
        $url = false;
    }
    return $url
}

$a = getUrl();

while($a !== $a = rtrim($a, '/'));

So the string can have a string value or a boolean value

There will be any unexpected result or downside when dealing with unexpected values of the string? (like specific strings, booleans values, integers, etc.?)

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
  • You should take a look at: [Sanitizing strings to make them URL and filename safe][1] [1]: http://stackoverflow.com/questions/2668854/sanitizing-strings-to-make-them-url-and-filename-safe – ADP_X Jul 09 '14 at 10:46
  • I would also add that I found the *rtrim/ltrim* functions to already strip multiple slashes. So my function is not really needed. Is not written into the documentation, but a test can easily show it. – Kamafeather Aug 18 '14 at 20:07

1 Answers1

0

Check if result is not false before moving forward,

$a = getUrl();
if($a){
   while($a !== $a = rtrim($a, '/'));
}
Rikesh
  • 26,156
  • 14
  • 79
  • 87