有没有办法使用PHP将“185,345,321”转换为185345321?
$str = "185,345,321";
$newStr = str_replace(',', '', $str); // If you want it to be "185345321"
$num = intval($newStr); // If you want it to be a number 185345321
$intV = intval(str_replace(",","","185,345,321"));
这里使用intval()
将string
转换为integer
。
$newString = str_replace(",", "", $integerString);
那么
$myNewInt = intval($newString);
是的,使用 str_replace()
示例:
str_replace( ",", "", "123,456,789");
Live example: http://ideone.com/Q7IAIN
$string= "185,345,321";
echo str_replace(",","",$string);
str_replace
或 preg_replace
都是可行的解决方案。$string = str_replace(",","","185,345,321");
之后,PHP 应该负责类型转换,因此您将处理一个整数。
$str = "185,345,321";
$newstr = str_replace(',','',$str);
echo $newstr;