How to Remove Special Characters from String in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Remove Duplicate Values from Array in PHP?
- How to Get Folder Path from File Path in PHP?
- How to Remove White Space from String in PHP?
- How to Check File is Exists or Not in PHP?
- How to Send Mail in PHP Laravel?
- How to Convert Object into Array in PHP?
- How to Add Prefix in Each Key of PHP Array?
- How to Get Minimum Key Value of Array in PHP?
- How to access PHP variables in JQuery?
- How to Get Product using Rakuten Marketing API in PHP?
- How to Count Number of Files in a Directory in PHP?
- How to Find Day Name from Specific Date in PHP?
- How to Remove Null Values from Array in PHP?