Join WhatsApp ChannelJoin Now

Special Characters Remove From String in PHP?

Hi Dev

Today, I will show you how to remove special characters from a string in PHP. This article will give you simple example of remove special characters from string in PHP. How would you remove special characters from a string in PHP?

we will use preg_replace() to remove special characters from string.

So, let’s follow few steps to create example of remove special characters from a string in PHP.

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 will assist you…

Recommended Posts