I am trying to parse following text in variable…
$str = 3,283,518(10,569 / 2,173)
And i am using following code to get 3,283,518
$arr = explode('(',$str);
$num = str_replace(',','',$arr[0]); //prints 3283518
the above $str is dynamic and sometimes it could be only 3,283,518(means w/o ()) so explode function will throw an error so what is the best way to get this value? thanks.
This will return 3283518, simply by taking the first part of the string
$strthat only consists of numbers and commas. This would also work for just3,283,518or3,283,518*10,569, etc.