我有一个包含如下所示行的文件:
{ “名”: “RandomName1”, “级别”:20, “阶级”: “东西”, “体验”:2688746894}, “账户”:{ “名”: “RandomAcc1”, “挑战”: { “总”:0}}},{ “在线”:假, “等级”:172, “死”:假, “字符”:
{ “名”: “RandomName2”, “级别”:21, “阶级”: “东西”, “体验”:2687863942}, “账户”:{ “名”: “RandomAcc2”, “挑战”: { “总”:0}}},{ “在线”:假, “等级”:173, “死”:假, “字符”:
{ “名”: “RandomAcc3”, “级别”:22, “阶级”: “东西”, “体验”:2687280914}, “账户”:{ “名”: “RandomAcc3”, “挑战”: { “总”:0}}},{ “在线”:假, “等级”:174, “死”:假, “字符”:
我想搜索名称,例如“RandomAcc3”,如果找到该名称,请检查该行中的“在线”状态并将其提取到布尔值中。非常感谢任何帮助!
答案 0 :(得分:0)
将文件json_decode读入数组,获取数组(foreach
)并检查当前子元素是否包含字符串(substr
/ preg_match
)。如果是这样,你会考虑/返回“在线”元素。希望你有一些编码技巧自己编写,否则使用codeacademy,而不是stackoverflow
答案 1 :(得分:0)
$fileContent = file_get_contents($filepath);
preg_match('/"name":"RandomAcc3"(.*)"online":([a-z]+)/i', $fileContent, $matches);
$onlineStatus = ($matches[2] == 'true');