Can't remove line breaks in php shell_exec() returnvalue

I am trying to grab some data from ifconfig but I only get the frist line stored in my variable.

I run

//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);

I only get the first line of the answer back. The full answer is:

eth
inet addr:192.168.99.193
RUNNING

But all I get in my variable is

eth

I have tried with php implode() and str_replace() to remove \n characters from $wlanTest but no luck.

Answers


First of all make sure that shell_exec() return you all data you need with var_dump because i see you command

egrep -o "wlan|inet addr:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|RUNNING"

select rows with wlan not eth, and then try to use this for replacement of line breaks $ethTest = preg_replace("/\r\n|\r|\n/",'',$ethTest)


Need Your Help

Casbah MongoDB update only certain fields

mongodb scala casbah

I'm using Casbah Scala driver to do CRUD operations on the MongoDB database. I would like to update a certain fields in a particular document. I'm using the findAndModify method, but to my surprise...

How to switch gridpaglayout panel on a jframe

java swing jpanel gridbaglayout

I have a jframe, and 4 jpanel with gridbaglayout. I want to switch from a jpanel to another with a click on a button. But instead of getting the first panel, I get the last one.