Php回声值不起作用

时间:2010-07-20 16:16:20

标签: php

这很好用

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

但这不是

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

如何让$ oscore等于从该脚本中提取的值:

    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 个答案:

答案 0 :(得分:1)

尝试将值转换为字符串,如下所示:

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

答案 1 :(得分:0)

尝试使用var_dump()而不是echo。你可能有一个由所有空格组成的字符串,不应该回应,但var_dump()会非常清楚。

如果您仍然没有看到任何内容,请确保它在您的功能中实际发生。 var_dump((string)$object->PresenceInfo->Info2);var_dump($object->PresenceInfo->Info2);(有和没有演员)。

干杯。