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)