In this blog, we will be going to remove special characters from strings in PHP. This will be very easy and simple to remove special characters from a string.
We will be going to use the function provided by PHP which will help to remove special characters that function is preg_replace().
Let's check the example,
Code:
<?php
$str = "Hello, This is #$#$ thecodingdev.com";
$newString = preg_replace('/[^A-Za-z0-9 ]/', '', $str);
echo $newString;
?>
Output:
Hello, This is thecodingdev.com
I hope this code will help. If you have any doubt let me know in comments.
0 Comments