There are some instances where you need to remove comma from a string or a number. For example, you would like PHP to convert 1,234 to 1234 and display to the browser. This where you need to remove commas…
Specifically, for computational purposes, PHP won’t include in the computation for numbers including a comma so you will need to remove it.
This type of application needs to use a PHP function called str_replace:
<?php
//check if post is submitted
if (!$_POST['submit']) {
//form not submitted show form
//entry field
echo '<form action="'.$SERVER['PHP_SELF'].'" method="post">';
echo 'Enter a string or a number containing commas, example 15,020: ';
echo '<input type="text" name="entry" size="20">';
echo '<br />';
echo '<input type="submit" name="submit" value="Submit">';
echo '</form>';
}
else {
//form submitted get data
$entry=trim($_POST['entry']);
//replace comma with space
$entry = str_replace(",", "",$entry);
//echo to the browser
echo '<br />'.$entry;
}
?>
In script above, it asks the user to input any string or number containing a comma, and then the PHP function first remove unnecessary spaces in the string using the trim command.
The PHP function str_replace:
$entry = str_replace(",", "",$entry);
The job is to detect any presence of commas in the variable, and then once it is detected, it will simply be removed. You can modify the above script to suit your own PHP application.

Very Helping script. One day ago I lost huge time for solving my problems. But now I founded very easy solution.
Thanks
That was awesome! Nice to hear that. Thanks for dropping my site jaheed
Hi Jaheed,
I am so happy to know that this script help someone. It just proves that anything I published in this site will be truly helpful and useful to visitors. Good luck with your projects!
Cheers,
Codex
This is a useful example. Thanks.
is there a way to create them into rows like
12
34
56
7890
from 12,34,56,78990 ?? any help is much appreciated
How try replacing empty space with break lines such as this:
$entry = str_replace(",", "<br />",$entry);