Php Remove Special Characters From String

May 20, 2023 | Category : Other

Hey Artisan,Hello Folks,
In this example, I will show you php string remove special characters. I’m going to show you about php remove special characters from string. I would like to show you how to remove special characters from a string in php. We will look at an example of remove special characters from string php. Follow the below tutorial step of remove some special characters from string php.

In this example, i will give you very simple example of how to remove special characters from a string in php. we will use preg_replace()

to remove special characters from string. so, let's see the example code with output:

index.php

<?php

$str = "Hello, How are you $##%% my friends?";

$cleanString = preg_replace('/[^A-Za-z0-9 ]/', '', $str);

echo $cleanString;

?>

Output:

Hello How are you my friends

I hope it can help you...