Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a comma separated string to int PHP? [duplicate]

Tags:

string

php

int

Is there any way you can convert "185,345,321" to 185345321 by using PHP?

like image 704
user2562125 Avatar asked Oct 15 '13 19:10

user2562125


2 Answers

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
like image 91
Misha Zaslavsky Avatar answered Oct 05 '22 08:10

Misha Zaslavsky


This can be achieved by-

$intV = intval(str_replace(",","","185,345,321"));

Here intval() is used to convert string to integer.

like image 23
ritesh Avatar answered Oct 05 '22 09:10

ritesh