Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to remove all special characters from a string using PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 271
    Comment on it

    Hello Reader! If you want to remove all of the special charracter from a given string then PHP offers you to use 'preg_replace';

    Lets see the example below:-

    $GivenString = 'a2|"dM!@PO^&$f 12~';
        $NewString = preg_replace('/[^A-Za-z0-9\. -]/', '', $GivenString);
    echo $NewString;
    

    Output:-

    a2dMPO 12
    

    Now in another case if you want replace all space with other symbol then you can use the syntax below:-

    $str = preg_replace('/  */', '-', $str);
    

 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: