note 111226 deleted from function.http-parse-headers by sobak

From: Date: Sun, 04 Dec 2016 07:22:17 +0000
Subject: note 111226 deleted from function.http-parse-headers by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208063@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- This one works even better: <?php function http_parse_headers( $header ) { $retVal = array(); $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header)); foreach( $fields as $field ) { if( preg_match('/([^:]+): (.+)/m', $field, $match) ) { $match[1] = preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1]))); if( isset($retVal[$match[1]]) ) { if (!is_array($retVal[$match[1]])) { $retVal[$match[1]] = array($retVal[$match[1]]); } $retVal[$match[1]][] = $match[2]; } else { $retVal[$match[1]] = trim($match[2]); } } } return $retVal; } ?>

« previous php.notes (#208063) next »