w3resource
php Programming Exercies

PHP String Exercises : Remove comma(s) from the specified numeric string

PHP String: Exercise-25 with Solution

Write a PHP script to remove comma(s) from the following numeric string.

Sample String : '2,543.12'

Pictorial Presentation:

PHP String Exercises: Remove comma(s) from the specified numeric string

Sample Solution:

PHP Code:

<?php
$str1 = "2,543.12";
$x = str_replace( ',', '', $str1);
if( is_numeric($x))
  {
  echo $x."\n";
  }
?>

Sample Output:

2543.12 

Flowchart :

Flowchart: Remove comma(s) from the specified numeric string

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to select first 5 words from the specified string.
Next: Write a PHP script to print letters from 'a' to 'z'.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming