Получить заголовок http ответа с помощью curl

0

Я использую curl --interface ip_goes here -I -L https://www.youtube.com/ чтобы получить заголовки http, но я хочу сохранить HTTP/1.1 200 OK в переменной. Я могу сделать это с помощью preg_match но мне интересно, есть ли более эффективное решение

HTTP/1.1 200 OK
Date: Fri, 09 Jan 2015 05:49:12 GMT
Server: gwiseguy/2.0
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
X-Frame-Options: SAMEORIGIN
Expires: Tue, 27 Apr 1971 19:44:06 EST
P3P: CP="This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=en for more info."
X-XSS-Protection: 1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube
X-Content-Type-Options: nosniff
Alternate-Protocol: 443:quic,p=0.02
Transfer-Encoding: chunked
Set-Cookie: YSC=zCtzROldgfs; path=/; domain=.youtube.com; HttpOnly
Set-Cookie: VISITOR_INFO1_LIVE=Oz-yH5fLujM; expires=Wed, 09-Sep-2015 17:42:11 GMT; path=/; domain=.youtube.com
Теги:
curl

2 ответа

1
Лучший ответ

используйте эту команду

curl --interface ip_goes_here -s -I -L https://www.youtube.com/ | глава -1

обратите внимание на дополнительный -s для бесшумного

0

Попробуй это:

$str="HTTP/1.1 200 OK
Date: Fri, 09 Jan 2015 05:49:12 GMT
Server: gwiseguy/2.0
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
X-Frame-Options: SAMEORIGIN 
more string....";
    $a=explode("\n",$str);
    var_dump($a[0]);

Выход: string 'HTTP/1.1 200 OK'

Ещё вопросы

Сообщество Overcoder
Наверх
Меню