dongxiang5879 2010-07-20 08:16
浏览 44
已采纳

Php回声值不起作用

This works just fine

<?php echo $response->user->last_game; ?>

but this doesn't

$oscore=$response->user->current_game;

How can I get $oscore to equal that value pulled from this script:

    private function clean_dirty_response($object)
     {
    // The final object
    $final_object = new StdClass();

    // Convert the XML to an object
    $object = simplexml_load_string($object);

    // Now that we've converted the XML to an object we can start shifting things around
    $final_object->user->membership_status  = (string)$object->AccountStatus;
    $final_object->user->last_game          = str_replace('   ',' ', (string)$object->PresenceInfo->Info); // For some reason there's some extra whitespace that needs to be removed
    $final_object->user->current_game           = str_replace('   ',' ', (string)$object->PresenceInfo->Info2); // For some reason there's some extra whitespace that needs to be removed
    $final_object->user->last_seen          = (string)$object->PresenceInfo->LastSeen;
    $final_object->user->online             = (string)$object->PresenceInfo->Online;
    $final_object->user->status_text        = (string)$object->PresenceInfo->StatusText;
    $final_object->user->title              = (string)$object->PresenceInfo->Title;
    $final_object->user->gamertag           = (string)$object->Gamertag;
    $final_object->user->profile_url        = (string)$object->ProfileUrl;
    // Jezus christ, why capitalize every freaking word? Just use lowercase next time you damn API!
    $final_object->user->profile_picture    = (string)$object->TileUrl;
    $final_object->user->avatar             = 'http://avatar.xboxlive.com/avatar/' . str_replace(' ', '%20', $final_object->user->gamertag) . '/avatar-body.png';
    $final_object->user->country            = (string)$object->Country;
    $final_object->user->reputation         = (int)$object->Reputation;
    $final_object->user->bio                = (string)$object->Bio;
    $final_object->user->location           = (string)$object->Location;
    $final_object->user->reputation_image   = (string)$object->ReputationImageUrl;
    $final_object->user->gamerscore         = (string)$object->GamerScore;
    $final_object->user->zone               = (string)$object->Zone;

    // Now it's time to clean the RecentGames part  
    $final_object->recent_games             = array();
    $i                                      = 0;

    // Loop through each game and clean it up
    foreach ($object->RecentGames->XboxUserGameInfo as $recent_game)
    {
        $obj = new stdClass();

        $obj->name                  = (string)$recent_game->Game->Name;
        $obj->achievements          = (int)$recent_game->Achievements;
        $obj->total_achievements    = (int)$recent_game->Game->TotalAchievements;
        $obj->gamerscore            = (int)$recent_game->GamerScore;
        $obj->total_gamerscore      = (int)$recent_game->Game->TotalGamerScore;
        $obj->thumb_32              = (string)$recent_game->Game->Image32Url;
        $obj->thumb_64              = (string)$recent_game->Game->Image64Url;

        // Format the date
        $raw_date           = (string)$recent_game->LastPlayed;
        $raw_date           = explode('T', $raw_date);
        $date               = $raw_date[0];
        // Time
        $raw_time           = $raw_date[1];
        $raw_time           = explode('+', $raw_time);
        $time               = $raw_time[0];
        // Offset
        $offset             = $raw_time[1];
        $obj->last_played   = array('date' => $date, 'time' => $time, 'offset' => $offset);
        $obj->details_url   = (string)$recent_game->DetailsURL;

        $final_object->recent_games[$i] = $obj;

        // counter + 1
        ++$i;
    }

    return $final_object;
}

展开全部

  • 写回答

2条回答 默认 最新

  • dongtan7998 2010-07-20 10:56
    关注

    Try converting the value to a string, like so:

    $oscore = strval($response->user->current_game);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部