strago Posted January 24, 2011 Share Posted January 24, 2011 I can' t even get the simple str_replace to work. I got.... $rslt = $client->getTodaySubIDStats($key, $sub_id); $rslt = str_replace("EARNINGS",'',$rslt); $rslt = str_replace("Array","",$rslt); $rslt = str_replace("\r","",$rslt); $rslt = str_replace("\n","",$rslt); $rslt = str_replace("\t","",$rslt); print_r($rslt); which spits out.... Array ( [0] => Array ( [EARNINGS] => $100.40 [CLICKS] => 1301 [LEADS] => 100 [sUB_ID] => yacker [EPC] => $0.11 ) ) I would like to have every thing removed except the '$100.40' (The number is always changing). Then remove the $ and do math 100.40*.40, so in the end, all it spits out is 40.16 and always only have two digits after the period. Quote Link to comment https://forums.phpfreaks.com/topic/225511-search-and-replace-then-do-math/ Share on other sites More sharing options...
Roman Fedorov Posted January 24, 2011 Share Posted January 24, 2011 Ehm.. the $rslt you are using i guess is not a string, thats why you cant process it with str_replace, it is a double array, and the print_r function you use prints the array structure. If you need to get the $ value you can just use $price = $rslt[0]['EARNINGS']; Quote Link to comment https://forums.phpfreaks.com/topic/225511-search-and-replace-then-do-math/#findComment-1164480 Share on other sites More sharing options...
strago Posted January 24, 2011 Author Share Posted January 24, 2011 Wow!! Thanks!! That was *really* easy!!! $price = $rslt[0]['EARNINGS']; $price = str_replace("$",'',$price); $sum_total = $price * .40; print_r($price); echo "$"; print_r($sum_total); Quote Link to comment https://forums.phpfreaks.com/topic/225511-search-and-replace-then-do-math/#findComment-1164487 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.