【发布时间】:2015-12-04 09:18:37
【问题描述】:
我正在尝试从 ifconfig 中获取一些数据,但我只将第一行存储在我的变量中。
我跑
//First off, find out whether we're using eth or wlan
$wlanTest = shell_exec('/sbin/ifconfig wlan|egrep -o "wlan|inet addr:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|RUNNING"');
$log = "| contents of wlan test: " . $wlanTest;
echo $log;
myLog($log);
我只得到答案的第一行。完整的答案是:
eth
inet addr:192.168.99.193
RUNNING
但我在变量中得到的只是
eth
我尝试使用 php implode() 和 str_replace() 从 $wlanTest 中删除 \n 字符,但没有成功。
【问题讨论】:
-
您是否尝试将 / 替换为 //?
-
不,这是 linux cmd 提示符中的特殊换行符吗?我只知道 \n 用于 linux 换行符。
标签: php linux shell exec line-breaks