我在 Windows 上使用 PHP 5.3.5,但我没有找到任何适用于我的安装的 pecl_http.dll
。
所以我的问题是,
如何获得 http_parse_headers
的功能不使用 PECL?
最佳答案
从文档页面,第一条评论:
if( !function_exists( 'http_parse_headers' ) ) {
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]]) ) {
$retVal[$match[1]] = array($retVal[$match[1]], $match[2]);
} else {
$retVal[$match[1]] = trim($match[2]);
}
}
}
return $retVal;
}
}
或者,您可能想阅读如何在 Windows 上安装 PECL 扩展,老实说,我对此一无所知。
关于php - 如何在没有 PECL 的情况下获得 http_parse_headers 的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6368574/