在else语句中PHP isset get issue error

aja*_*kuv 1 php isset

我试图得到它所以index.php?steamusr =用户名得到的设置为var,如果没有指定它只显示在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&currency=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>';
}
}
?>
Run Code Online (Sandbox Code Playgroud)

这是错误:

[Wed Aug 19 09:24:33.723604 2015] [:error] [pid 21378] [client 67.90.138.68:62702] PHP解析错误:语法错误,/ var/www/index.php中意外的'else'(T_ELSE)在第58行

Fun*_*ner 5

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&currency=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>';
}

?>
Run Code Online (Sandbox Code Playgroud)