我试图得到它所以index.php?Steamusr =username = get被设置为var,如果没有指定,它只显示一个在else语句中指定的错误。
我已经试过了,如果是空的和isset。我已经尝试了我能找到的每一种组合,但仍然一无所获。这是我现在的代码,下面是错误信息。谢谢!
<?php
if (isset($_GET['steamusr'])) {
$user = $_GET['steamusr'];
$myinv = 'http://steamcommunity.com/id/$user/inventory/json/295110/1/';
$content2 = file_get_contents($myinv);
$json2 = json_decode($content2, true);
$imgurlbase = 'http://steamcommunity-a.akamaihd.net/economy/image/';
foreach($json2['rgDescriptions'] as $i){
$item = $i['market_name'];
$icon = $i['icon_url'];
$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=' . urlencode($item);
$grab = file_get_contents($fetchdata);
$id = json_decode($grab, true);
echo '<img src="'. $imgurlbase . $icon . '/64fx64f">' . '<a class="btn btn-primary btn-lg" href="#" role="button">'.'<span class="badge">1</span> ' . $item .'</a>' . '<a class="btn btn-primary btn-lg" href="#" role="button">'.'Low</br>'. $id['lowest_price'].'</a>'.'<a class="btn btn-primary btn-lg" href="#" role="button">'.'Avg</br>'. $id['median_price'].'</a>'.'<br>';
}
else {
echo '<h1>No steam user set</h2>';
}
}
?>
错误如下:
[Wed Aug 19 09:24:33.723604 2015] [:error] [pid 21378] [client 67.90.138.68:62702] PHP解析错误:语法错误,unexpected 'else' (T_ELSE) in/var/www/index. PHP on line 58
else
部分与第一个条件语句一起工作,因此它需要放在最后一个大括号之后。
<?php
if (isset($_GET['steamusr'])) {
$user = $_GET['steamusr'];
$myinv = 'http://steamcommunity.com/id/$user/inventory/json/295110/1/';
$content2 = file_get_contents($myinv);
$json2 = json_decode($content2, true);
$imgurlbase = 'http://steamcommunity-a.akamaihd.net/economy/image/';
foreach($json2['rgDescriptions'] as $i){
$item = $i['market_name'];
$icon = $i['icon_url'];
$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=' . urlencode($item);
$grab = file_get_contents($fetchdata);
$id = json_decode($grab, true);
echo '<img src="'. $imgurlbase . $icon . '/64fx64f">' . '<a class="btn btn-primary btn-lg" href="#" role="button">'.'<span class="badge">1</span> ' . $item .'</a>' . '<a class="btn btn-primary btn-lg" href="#" role="button">'.'Low</br>'. $id['lowest_price'].'</a>'.'<a class="btn btn-primary btn-lg" href="#" role="button">'.'Avg</br>'. $id['median_price'].'</a>'.'<br>';
}
// else was here before
} else {
echo '<h1>No steam user set</h2>';
}
?>
修改这部分代码:
foreach($json2['rgDescriptions'] as $i){
$item = $i['market_name'];
$icon = $i['icon_url'];
$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=' . urlencode($item);
$grab = file_get_contents($fetchdata);
$id = json_decode($grab, true);
echo '<img src="'. $imgurlbase . $icon . '/64fx64f">' . '<a class="btn btn-primary btn-lg" href="#" role="button">'.'<span class="badge">1</span> ' . $item .'</a>' . '<a class="btn btn-primary btn-lg" href="#" role="button">'.'Low</br>'. $id['lowest_price'].'</a>'.'<a class="btn btn-primary btn-lg" href="#" role="button">'.'Avg</br>'. $id['median_price'].'</a>'.'<br>';
}
else {
echo '<h1>No steam user set</h2>';
}
}
foreach($json2['rgDescriptions'] as $i){
$item = $i['market_name'];
$icon = $i['icon_url'];
$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=' . urlencode($item);
$grab = file_get_contents($fetchdata);
$id = json_decode($grab, true);
echo '<img src="'. $imgurlbase . $icon . '/64fx64f">' . '<a class="btn btn-primary btn-lg" href="#" role="button">'.'<span class="badge">1</span> ' . $item .'</a>' . '<a class="btn btn-primary btn-lg" href="#" role="button">'.'Low</br>'. $id['lowest_price'].'</a>'.'<a class="btn btn-primary btn-lg" href="#" role="button">'.'Avg</br>'. $id['median_price'].'</a>'.'<br>';
}
}
else {
echo '<h1>No steam user set</h2>';
}
现在你把else放在foreach后面,而不是if。