vishavjeet

singh.vishavjeet11@gmail.com

How can Remove all special characters from a string using php

Posted on February 22, 2021



function clean($string) {


$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.


return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.


}


echo clean('a|"bc!@┬úde^&$f g hij|!##');  // abcdefghij


echo clean('&&&week_!-15 95 497739.jpg'); // week1595497739


Sign In for comment and like the post.