note 94717 deleted from function.http-parse-headers by danbrown

From: Date: Thu, 19 Nov 2009 21:21:11 +0000
Subject: note 94717 deleted from function.http-parse-headers by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163112@lists.php.net to get a copy of this message
Note Submitter: alejosimon ---- This works fine. <?php /** * Extract the headers content from a response string. * * @param String raw response. * @return Array value. */ function extractHeaders( $response ) { $headers = array() ; $fields = explode( "\n", $response ) ; foreach ( $fields as $field ) { $field = trim( $field ) ; if ( $field == '' ) break ; if ( preg_match( '/^([\w-]+):\s+(.+)/', $field, $matches ) ) { list( $match, $name, $value ) = $matches ; if ( isset( $headers[ $name ] ) ) { $headers[ $name ] = (array) $headers[ $name ] ; $headers[ $name ][] = $value ; } else { $headers[ $name ] = $value ; } } } return $headers ; } ?>

« previous php.notes (#163112) next »