有什么方法可以使用 PHP 将“185,345,321”转换为 185345321?
问问题
13601 次
8 回答
9
Yes, it's possible:
$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
于 2013-10-15T19:28:51.600 回答
8
这可以通过-
$intV = intval(str_replace(",","","185,345,321"));
这里intval()
用于转换string
为integer
.
于 2013-10-15T19:29:49.937 回答
5
You can get rid of the commas by doing
$newString = str_replace(",", "", $integerString);
then
$myNewInt = intval($newString);
于 2013-10-15T19:28:37.820 回答
4
Yes, use str_replace()
Example:
str_replace( ",", "", "123,456,789");
Live example: http://ideone.com/Q7IAIN
于 2013-10-15T19:28:25.473 回答
4
$string= "185,345,321";
echo str_replace(",","",$string);
于 2013-10-15T19:29:29.417 回答
3
You can use string replacement, str_replace
or preg_replace
are viable solutions.
$string = str_replace(",","","185,345,321");
PHP should take care of type casting after that so you deal with an integer.
于 2013-10-15T19:28:28.300 回答
3
$str = "185,345,321";
$newstr = str_replace(',','',$str);
echo $newstr;
于 2013-10-15T19:28:50.367 回答
3
str_replace(",","","185,345,321")
于 2013-10-15T19:29:50.137 回答