Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Remove all special charracters and replace white spaces with hyphen "-" using PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 115
    Comment on it

    Hello Readers! if you want to replace all the sepecial charracters from a string and replace white space by hyphen '-' then the code below will help you to learn:-

    first we will replace all the white space with hyphen "-" from the string

    function clean($string) {
       $string = str_replace(' ', '-', $string);
    
       return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Now removes special chars.
    }
    
    echo clean('9|"99b7!@9d^&$mD W');
    

    Output:-

    99b79dMd-W
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: