我使用cURL和zend框架,它给了我回头和网站内容。
我在另一个类中使用此输出,我想从curl输出中提取标题,以查看语言是否为ser(内容语言)。
输出有受保护的类,例如响应和标题,我试图设置类标题和响应以尝试获取标题值,但它没有给我任何结果。
(curl output => $ this-> content)
class Zend\Http\Response#258 (7) { protected $recommendedReasonPhrases => array(57) { [100] => string(8) "Continue"
[101] => string(19)" Switching Protocols" [102] =>串(10) "处理" [200] => string(2)" OK" [201] => string(7)" Created" [202] => string(8)" Accepted" [203] =>字符串(29)"非权威 信息" [204] =>字符串(10)"没有内容" [205] =>串(13) "重置内容" [206] =>字符串(15)"部分内容" [207] => 字符串(12)"多状态" [208] =>字符串(16)"已报告" [300] => string(16)" Multiple Choices" [301] =>字符串(17)"永久移动" [302] =>字符串(5)"找到" [303] => string(9)"见其他" [304] =>字符串(12)"未修改" [305] => string(9)" Use Proxy" [306] => string(12)" Switch Proxy" [307] =>字符串(18)"临时 重定向" [400] => string(11)" Bad Request" [401] =>串(12) "未授权" [402] =>字符串(16)"需要付款" [403] => 字符串(9)"禁止" [404] =>字符串(9)"未找到" [405] => 字符串(18)"方法不允许" [406] =>字符串(14)"不可接受" [407] =>字符串(29)"需要代理验证" [408] => string(16)" Request Time-out" [409] =>字符串(8)"冲突" [410] => string(4)" Gone" [411] => string(15)" Length Length" [412] => string(19)" Precondition Failed" [413] =>字符串(24)"请求实体 太大" [414] => string(21)" Request-URI Too Large" [415] => 字符串(22)"不支持的媒体类型" [416] =>字符串(31)"请求 范围不满意" [417] =>字符串(18)"期望失败" [418] =>字符串(12)"我是一个茶壶" [422] => string(20)" Unprocessable Entity" [423] => string(6)" Locked" [424] => string(17)"失败 依赖" [425] => string(20)" Unordered Collection" [426] => string(16)"需要升级" [428] =>字符串(21)"前提条件 所需" [429] =>字符串(17)"请求太多" [431] =>串(31) "请求标题字段太大" [500] => string(21)" Internal Server 错误" [501] =>字符串(15)"未实现" [502] => string(11)" Bad 网关" [503] =>字符串(19)"服务不可用" [504] =>串(16) "网关超时" [505] => string(26)"不支持HTTP版本" [506] =>字符串(23)"变体也谈判" [507] =>串(20) "存储不足" [508] => string(13)" Loop Detected" [511] => 字符串(31)"需要网络验证" } protected $ statusCode => int(200)protected $ reasonPhrase => string(2)" OK" protected $ version => string(3)" 1.1" protected $ headers =>类 Zend \ Http \ Headers#257(3){protected $ pluginClassLoader =>空值 protected $ headersKeys => array(15){[0] => string(4)" date" [1] => string(6)" server" [2] => string(10)" xpoweredby" [3] =>串(12) " xdrupalcache" [4] =>字符串(7)"到期" [5] =>串(12) "上次更改时间" [6] => string(12)" cachecontrol" [7] =>串(4) " ETAG" [8] => string(15)" contentlanguage" [9] =>串(10) " xgenerator" [10] =>字符串(4)"变化" [11] =>串(15) " contentencoding" [12] => string(13)" contentlength" [13] => 字符串(10)"连接" [14] => string(11)" contenttype"受保护的 $ headers => array(15){[0] =>数组(2){' name' =>字符串(4)"日期" '线' => string(35)" Date:Tue,26 Feb 2013 09:57:42 GMT" } [1] => 数组(2){' name' =>字符串(6)"服务器" '线' =>字符串(30)"服务器: Apache / 2.2.14(Ubuntu)" } [2] =>数组(2){' name' =>串(12) " X供电-通过" '线' =>字符串(35)" X-Powered-By: PHP / 5.3.2-1ubuntu4.18" } [3] =>数组(2){' name' =>串(14) " X-Drupal的高速缓存" '线' => string(20)" X-Drupal-Cache:MISS" } [4] => 数组(2){' name' =>字符串(7)"到期" '线' =>串(38) " Expires:Sun,1978年11月19日05:00:00 GMT" } [5] =>数组(2){' name' => string(13)" Last-Modified" '线' => string(46)" Last-Modified:Tue, 2013年2月26日09:57:42 + 0000" } [6] =>数组(2){' name' =>串(13) "缓存控制" '线' => string(32)" Cache-Control:public, 最大年龄= 0" } [7] =>数组(2){' name' =>字符串(4)" ETag" '线' => 字符串(20)" ETag:" 1361872662-1"" } [8] =>数组(2){' name' => string(16)" Content-Language" '线' => string(20)" Content-Language: RU" } [9] =>数组(2){' name' => string(11)" X-Generator" '线' => string(41)" X-Generator:Drupal 7(http://drupal.org)" } [10] => 数组(2){' name' => string(4)" Vary" '线' =>字符串(28)"变化: 饼干,接受编码" } [11] =>数组(2){' name' =>串(16) "内容编码" '线' => string(22)" Content-Encoding:gzip" } [12] =>数组(2){' name' => string(14)" Content-Length" '线' => 字符串(20)"内容长度:7139" } [13] =>数组(2){' name' => 字符串(10)"连接" '线' =>字符串(17)"连接:关闭" } [14] =>数组(2){' name' => string(12)" Content-Type" '线' => string(38)" Content-Type:text / html;字符集= UTF-8"受保护的 $ metadata => array(0){} protected $ content =>串(23711)
(代码)
$response = new Response();
$response->getHeaders($this->content);
$headers = new Headers();
var_dump($headers->get('Content-Language'));
(生成)
bool(false)
($ response的var_dump-> getHeaders)
类Zend \ Http \ Headers#259(3){protected $ pluginClassLoader =>空值 protected $ headersKeys => array(0){} protected $ headers =>阵列(0) {}}
提前致谢,
尼克
答案 0 :(得分:1)
您不应该构建新的Zend\Http\Response
,也不应该构建新的Zend\Http\Headers
,而只需使用当前上下文中$this->content
中已有的var_dump($this->content->getHeaders()->get('Content-Language'));
:
{{1}}