dongxiang5879 2010-07-20 16: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 18:56
    关注

    Try converting the value to a string, like so:

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

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么