Php文件只显示1号?

时间:2016-01-15 11:21:58

标签: php

所以我有一个Steam Market Price API,但是如果我通过我的PHP文件转到它,它将显示“1”。例如:cost.php?name = blablabla

<?php
if (isset($params,$item)){
$params['format'] = 'json';
$params['data'] =json_encode($package_data);
$item = $_GET['item'];
$item = str_replace("\"", "", $item);
$item = str_replace("\'", "", $item);
$item = str_replace(" ", "%20", $item);
$item = str_replace("\\", "", $item);
@include_once ("set.php");
$rs = mysql_query("SELECT * FROM items WHERE name='$item'");
$url = "http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=".$item;
if(mysql_num_rows($rs) > 0) {
    $row = mysql_fetch_array($rs);
    if(time()-$row["lastupdate"] < 3600) die($row["cost"]);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
$result = curl_exec($ch);
curl_close($ch);
$results = json_decode($result, true);
var_dump($results);
if($results->{'success'} == "0") die("notfound");{
$lowest_price = $results->{'median_price'};
$lowest_price[strlen($lowest_price)] = 0;
$lowest_price = str_replace("$","",$lowest_price);
$lowest_price = floatval($lowest_price);
}
mysql_query("DELETE FROM items WHERE name='$item'");
mysql_query("INSERT INTO items (`name`,`cost`,`lastupdate`) VALUES ('$item','$lowest_price','".time()."')");
print_r($results);  
}
?>

我的问题是,是否有人知道该解决方案?

1 个答案:

答案 0 :(得分:0)

$lowest_pricearray

$lowest_price = $obj->{'lowest_price'};
$lowest_price[strlen($lowest_price)] = 0; // <-- here you are making it into an array
$lowest_price = str_replace("$","",$lowest_price);
$lowest_price = floatval($lowest_price);

您正在向float投射,所以基本上该过程正常。

了解floatval行为http://php.net/manual/en/function.floatval.php#refsect1-function.floatval-returnvalues

的行为方式

您应该强制转换数组的值,或者只启用error_reporting来捕获所有通知。