Remove comma from a string in PHP?

To remove comma, you can replace. To replace, use str_replace() in PHP.

Let’s say the following is our input string with comma 


We want the output after removing comma from the above string is 



The PHP code is as follows

 Live Demo

<!DOCTYPE html>
$result = str_replace(',', '', $name);
echo "The actual value is=",$name,"<br>";
echo "After removing the comma(,)=",$result,"<br>";


This will produce the following output

The actual value is=John,Smith
After removing the comma(,)=JohnSmith

Updated on: 13-Oct-2020

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started