PHP remove commas from numeric strings

前端 未结 7 1483
悲哀的现实
悲哀的现实 2020-11-30 12:21

In PHP, I have an array of variables that are ALL strings. Some of the values stored are numeric strings with commas.

What I need:

A way to trim the comma

7条回答
  •  余生分开走
    2020-11-30 12:58

    The easiest would be:

    $var = intval(preg_replace('/[^\d.]/', '', $var));
    

    or if you need float:

    $var = floatval(preg_replace('/[^\d.]/', '', $var));
    

提交回复
热议问题