ItSolutionStuff.com

How to Remove Special Characters from String in PHP?

By Hardik Savani May 14, 2024
PHP

Hey Artisan,

In this tute, we will discuss php string remove special characters. This tutorial will give you a simple example of php remove special characters from string. I explained simply about how to remove special characters from a string in php. if you want to see an example of remove special characters from string php then you are in the right place.

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...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube