How to automatically delete special characters inside string variable and filter the whole string.
Cleaning up the string variable by removing special characters is very important thing in dynamic development area because when you are about to create dynamic website which servers pages into permalinks form then by mistake adding some special characters into it will make the url blocked. So with the help of special symbols cleaning method you can easily clean up any string variable. So here is the complete step by step tutorial for Remove all special characters from a string in PHP.
How to Remove all special characters from a string in PHP.
Code for string-clean-up.php file.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Remove all special characters from a string in PHP</title> </head> <body> <?php $demo1 = "Hello /\ [] PHP"; echo "Before Special characters Remove = " . $demo1 . '</br>' ; $newdemo = preg_replace('/[^a-zA-Z0-9]/s', '', $demo1); echo "After Special characters Remove = " . $newdemo ; ?> </body> </html>
Screenshot: