explode()ing for new rows ( \n) gives you an array with one element per row, and when you loop the array and use it preg_split("/\s+/", $sValue, 3), it should give you a new array with each column as an item. Then you need to separate the date and Addr.
The full code will look something like this:
<?php
$sTempUsers = shell_exec('who');
$aTempUsers = explode("\n", $sTempUsers);
$aUsers = array();
foreach($aTempUsers AS $sUser)
{
$aTempUser = preg_split("/\s+/", $sUser, 3);
preg_match("/^(.+)\s\((.+)\)$/", $aTempUser[2], $aDateAndAddr);
$aUsers[] = array(
$aTempUser[0],
$aTempUser[1],
$aDateAndAddr[1],
$aDateAndAddr[2]
);
}
?>
The result can be found in $aUsers.
source
share