php - 如何在没有 PECL 的情况下获得 http_parse_headers 的功能?

标签 php http

我在 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/

相关文章:

css - 内容安全策略 img-src 数据 url 哈希值

http - S3 : How to do a partial read/seek without downloading the complete file?

http - 更改 Netty 4 HTTP 文件服务器示例以使用 ChunkedStream 而不是 ChunkedFile

php - 如何禁用 symfony 中的表单元素?

php - 选定的自动完成值未显示在输入框中

javascript - 自动验证 htaccess (401) 用户名​​密码登录

javascript - 在 CodeIgniter 的 AJAX 成功函数中提交动态创建的表单

javascript - 使用ajax和php根据文本框更改更改查询

java - 允许在我的 java 网络服务器中浏览目录

http - 最小 http 服务器回复