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)