我正在尝试围绕 Miscrits: World Adventure 游戏制作一个 Facebook 应用程序 这个想法是制作一个 PVP 天梯。
为了使其正常工作,我希望应用程序自动获取玩家信息。 该信息存储在这里:http://miscrits.brokenbulbstudios.com/player/info (每个玩家都是独一无二的) 它返回的结果看起来像这样 > http://pennygasm.com/info.htm
有一个粗体区域,我将信息分开以便于阅读。 我需要将每个粗体值存储在变量中。这样我就可以进行一些计算并创建玩家排名等。
玩家将访问我的应用程序并单击“加入天梯”,然后它将从 Miscrits 网址获取信息。我猜玩家需要定期回来更新他们的信息?当用户访问页面时它可以自动更新...
无论如何......我如何将这些信息转化为一些变量?
最佳答案
这些字符串看起来像有效的 JSON。在 PHP 5.2+ 中,您可以使用 json_decode() 将 json 字符串转换为充满变量的对象/数组:)
看这个:
http://php.net/manual/en/function.json-decode.php
试试这个:
// grab the JSON data and stuff it in a variable
$json = file_get_contents("http://miscrits.brokenbulbstudios.com/player/info", true);
// decode to an associative array using json_decode()
$decoded = json_decode($json, true);
//check out what's in there
print_r($decoded);
关于php - 将字符串转换为变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4987825/