Search code examples
phpstripslashes

PHP such as stripslashes for forward slash?


Is there a similar option for removing forward slashes?

I have a text input that could be any manner of slashes:

e.g /slug/ or /slug or slug or slug/

I need to completely remove all forward slashes regardless of where they are. I know stripslashes will do this for \ slashes. Is there anything similar for forward?

Currently I have:

$successful_slug = stripslashes($input_successful_slug);

Solution

  • Just remove them using str_replace

    $successful_slug = str_replace('/', '', $input_successful_slug);
    

    If you want to remove only leading and trailing slashes (and leave those inside the string), use trim

    $successful_slug = trim($input_successful_slug, '/');