php remove comma from string – how to remove comma from string in php?

php remove comma from string. To remove comma or any special char, you can replace. To replace, use str_replace() in PHP. Then use trim() to remove unnecessary commas at the front or end of the string.

php remove comma from string

trim comma from variable in php


Remove comma from a string in PHP?


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

PHP remove commas from numeric strings


$a = "1,895";
$b = str_replace( ',', '', $a );

if( is_numeric( $b ) ) {
    $a = $b;

How to remove the last comma from a PHP foreach loop?

Remove the comma from the last item of PHP foreach loop

  $website_list = array("pakainfo", "w3diy", "infinityknow", "w3school", "blogspot", "example");
  $num_of_items = count($website_list);
  $num_count = 0;
  foreach ($website_list as $website) {
    echo $website;
    $num_count = $num_count + 1;
    if ($num_count < $num_of_items) {
      echo ", ";

Free Live Chat for Any Issue

Remove Last Comma From String Jquery

Also Read This 👉   ERROR 1118 (42000) Row size too large

remove comma from string php

Remove an item from comma separated string using PHP

function removeItemuser_line($str, $item) {
	$parts = explode(',', $str);
	while(($i = array_search($item, $parts)) !== false) {
	return implode(',, $parts);


$myuser_line = 'pakainfo,infinityknow,w3diy,w3school';
$result_user_line = removeItemuser_line($myuser_line, "mouse");
echo "Input user_line: ".$myuser_line;
echo “Output user_line: ".$result_user_line;

I hope you get an idea about php remove comma from string.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.