0
mailq
명령을 실행하고 다차원 배열의 값으로 출력하는 데 문제가 있습니다.PHP가 "mailq"명령의 출력을 배열로 가져 오는 중
$results = array();
exec('/usr/bin/mailq', $mailQresult);
foreach ($mailQresult as $key => $mailqLine) {
$res = preg_match('/^([A-Z0-9]{1,20})\s+([1-9][0-9]*)\s+((Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s+[A-Za-z]{3}\s+[0-9]{2}\s+[0-9]{2}\:[0-9]{2}\:[0-9]{2})\s*$/', $mailqLine, $matches);
if ($res) {
// Insert message ID and other data into the object.
// It will be competed afterwards.
$mailqArray = array(
'id' => $matches[1],
'size' => intval($matches[2]),
'date' => strftime($matches[3]),
'sender' => $matches[5],
'failed' => false,
'recipients' => $matches[4]
);
}
}
mailq
의 출력은 공백 및 수익을 포함하고이 같은 비트 같습니다
ID SIZE DAYNAME MONTH DAY HOUR:MINUTES:SECONDS [email protected] [new line here]
(Host or domain name not found. Name service error for name=address.com type=MX: Host not found, try again) [new line here]
[email protected]
그렇게 오류 메시지와 수신자 (가) 다른 키에서 생을 마감합니다.
나는 shell_exec을 사용하여 mailq의 결과를 한 문자열로 얻을 수 있지만 다차원 배열을 만드는 정규 표현식을 작성하는 방법을 알지 못한다.
내가 잘못 접근하고 있습니다. 모든 조언은 대단히 환영합니다!