EDIT: Problem is (semi) fixed. Now when I cast the string it becomes and itege
I'm trying to fetch a series of pieces of data from the Steam website. One of these pieces of data is the price.
The web request I am making returns something similar to the following:
class=\"market_table_value\">\r\n\t\t\t\tStarting at:<br\/>\r\n\t\t\t\t<spanstyle=\"color:white\">$9.05 USD<\/span>\r\n\t\t\t<\/span>\r\n\t\t\t<span
This is not the whole return, but it is the relevant section.
So I then use the following method to store it in an array (since the request usually has multiple items returned)
preg_match_all('#Starting\s*at:<br/>\r\n\t\t\t\t(.*)\t\t\t</span>#siU',$res->results_html, $sor);
foreach($sor[1] as $k => $v)
$objects[$k]['price'] = $v; //str_replace('$', '', $v);
... and then I write object to a data.json file. Here is the formatting of the data.json (the relevant section.)
"price":"<span style=\"color:white\">$0.48<\/span>\r\n"
The problem is, that when I try to cast the price into a float it returns 0. Here is my code for that section.
foreach($decodedfile as $datas) {
$tmp = preg_replace(array("/[^0-9,.]/"), "", $datas->price);
$ourprice = (float)$tmp;
$sql2 = ("INSERT INTO Products (FileID, FileName, FileCat, FileType, FileMethod, FilePrice) VALUES ('".$id."', '".$datas->name."', '12', 'Rifle', 'email', '".$ourprice."')");
The '$decodedfile' is simply the json_decode'd data.json.
So, my real question is, why when I cast it to a float does it become 0?