gpt4 book ai didi

java - 如何将网络上的adb设备列表存储到php数组中

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:14:40 25 4
gpt4 key购买 nike

运行命令:

$output = shell_exec("adb devices -l");

echo "$output";

得到这样的输出:

List of devices attached
10.16.21.138:5555 device product:tbltevzw model:SM_N915V device:tbltevzw
10.16.20.90:5555 device product:ghost_verizon model:XT1060 device:ghost

有人可以帮助将这些信息存储到 php 关联数组中吗?

最佳答案

// remove extra spaces, then split into array by new lines
$arr = explode("\n", preg_replace('/ +/',' ',$x));
array_shift($arr); // remove 1-st line
$result = Array();
foreach($arr as $v)
{
$tmp = explode(' ',$v); // split each line into words
list($ip,$port) = explode(':',$tmp[0]);
$item = Array('ip'=>$ip, 'port'=>$port);
array_shift($tmp); // remove IP:PORT
array_shift($tmp); // remove DEVICE
foreach($tmp as $n)
{
list($key,$data) = explode(':',$n); // split by :
$item[$key] = $data; // accumulate key/data pairs
}
$result[] = $item; // append device to the result array
}

关于java - 如何将网络上的adb设备列表存储到php数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38692741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com