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

运行命令:

$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
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...