Jump to content

Search and replace, then do math.


strago

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/225511-search-and-replace-then-do-math/
Share on other sites

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'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.