note 103007 modified in function.httpmessage-getheader by thiago

From: Date: Mon, 21 Mar 2011 14:10:47 +0000
Subject: note 103007 modified in function.httpmessage-getheader by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178049@lists.php.net to get a copy of this message
This can be good to ping external web sites, get the content type, length, etc. <?php function get_http_header( $strUrl ) { $arrHeader = array(); $arrHeader[ 'url' ] = $strUrl; try { $arrLines = explode( "\n" , http_head( $strUrl ) ); } catch( Exception $objException ) { return array( "response" => "timeout" , "url" => $strUrl ); } $arrHeader['response'] = array_shift( $arrLines ); foreach( $arrLines as $strLine ) { $arrLine = explode( ":" , $strLine ); if( sizeof( $arrLine ) == 2 ) { $arrHeader[ $arrLine[0] ] = $arrLine[1]; } } return $arrHeader; } print_r( get_http_header( "http://www.example.com" ) ); ?> Array ( [url] => http://www.example.com [response] => HTTP/1.1 200 OK [Server] => Microsoft-IIS/5.0 [X-Powered-By] => ASP.NET [Content-Type] => text/html [Accept-Ranges] => bytes [Content-Length] => 465 --was-- This can be good to ping external web sites, get the content type, length, etc. <?php function get_http_header( $strUrl ) { $arrHeader = array(); $arrHeader[ 'url' ] = $strUrl; try { $arrLines = explode( "\n" , http_head( $strUrl ) ); } catch( Exception $objException ) { return array( "response" => "timeout" , "url" => $strUrl ); } $arrHeader['response'] = array_shift( $arrLines ); foreach( $arrLines as $strLine ) { $arrLine = explode( ":" , $strLine ); if( sizeof( $arrLine ) == 2 ) { $arrHeader[ $arrLine[0] ] = $arrLine[1]; } } return $arrHeader; } print_r( get_http_header( "http://www.example.com" ) ); ?> Array ( [url] => http://www.pudim.com.br [response] => HTTP/1.1 200 OK [Server] => Microsoft-IIS/5.0 [X-Powered-By] => ASP.NET [Content-Type] => text/html [Accept-Ranges] => bytes [Content-Length] => 465 http://php.net/manual/en/function.httpmessage-getheader.php

« previous php.notes (#178049) next »