fork download
  1. <?php
  2. $stdin = fopen('php://stdin', 'r');
  3. function getResponse($socet) {
  4. $response = '';
  5. while(($str = fgets($socet)) !== false) {
  6. $response .= $str;
  7. }
  8. return $response;
  9. }
  10. function getData($response) {
  11. $data = array();
  12. $matches = array();
  13. $count = preg_match_all('/(\d{3,})(\s|-)(.*)/', $response, $matches, PREG_PATTERN_ORDER);
  14. for($i = 0; $i < $count; $i++) {
  15. $data[$i]['code'] = $matches[1][$i];
  16. $data[$i]['message'] = $matches[3][$i];
  17. }
  18. return $data;
  19. }
  20. var_dump(getData(getResponse($stdin)));
Success #stdin #stdout 0.01s 20520KB
stdin
250-smtp25.mail.ru
250-SIZE 73400320
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN XOAUTH2
250 STARTTLS
stdout
array(6) {
  [0]=>
  array(2) {
    ["code"]=>
    string(3) "250"
    ["message"]=>
    string(14) "smtp25.mail.ru"
  }
  [1]=>
  array(2) {
    ["code"]=>
    string(3) "250"
    ["message"]=>
    string(13) "SIZE 73400320"
  }
  [2]=>
  array(2) {
    ["code"]=>
    string(3) "250"
    ["message"]=>
    string(8) "8BITMIME"
  }
  [3]=>
  array(2) {
    ["code"]=>
    string(3) "250"
    ["message"]=>
    string(10) "PIPELINING"
  }
  [4]=>
  array(2) {
    ["code"]=>
    string(3) "250"
    ["message"]=>
    string(24) "AUTH PLAIN LOGIN XOAUTH2"
  }
  [5]=>
  array(2) {
    ["code"]=>
    string(3) "250"
    ["message"]=>
    string(8) "STARTTLS"
  }
}