How to remove special characters from string using php?

    To remove special characters from string use preg_replace like this
    <?php
      $mydata
    = 'this is @ test & Strings';

     
    $mydata = preg_replace("/[^a-zA-Z0-9s]/", "", $mydata);

     
    //print $mydata; will output "thisistestStrings"
    ?>
    5
    Average: 5 (1 vote)