首頁  >  文章  >  後端開發  >  求挽救匹配PHP字符串中的cookie

求挽救匹配PHP字符串中的cookie

WBOY
WBOY原創
2016-06-13 11:50:48956瀏覽

求补救匹配PHP字符串中的cookie
下面这是一段PHP字符串:
HTTP/1.1 200 OK Date: Wed, 12 Mar 2014 11:57:58 GMT Server: Apache/2.2.9 (APMServ) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6 X-Powered-By: PHP/5.2.6 Cache-Control: public,max-age=10 Last-Modified: Wed, 12 Mar 2014 11:57:59 GMT Set-Cookie: session=cef14157b685078cf9c8f5d66fcefa81116a180d%7E53204bc7209fe349757896; expires=Wed, 12-Mar-2014 13:57:59 GMT; path=/; domain=.*****.com Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 

我想用php正则匹配出这段字符串:
Set-Cookie: session=cef14157b685078cf9c8f5d66fcefa81116a180d%7E53204bc7209fe349757896;

求补救!
------解决方案--------------------

$str = "HTTP/1.1 200 OK Date: Wed, 12 Mar 2014 11:57:58 GMT Server: Apache/2.2.9 (APMServ) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6 X-Powered-By: PHP/5.2.6 Cache-Control: public,max-age=10 Last-Modified: Wed, 12 Mar 2014 11:57:59 GMT Set-Cookie: session=cef14157b685078cf9c8f5d66fcefa81116a180d%7E53204bc7209fe349757896; expires=Wed, 12-Mar-2014 13:57:59 GMT; path=/; domain=.*****.com Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 ";<br />preg_match("/Set-Cookie:\s*session=[^;]+/i", $str,$match) ;<br />var_dump($match[0]);

------解决方案--------------------
$s=<<< TXT<br />HTTP/1.1 200 OK Date: Wed, 12 Mar 2014 11:57:58 GMT Server: Apache/2.2.9 (APMServ) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6 X-Powered-By: PHP/5.2.6 Cache-Control: public,max-age=10 Last-Modified: Wed, 12 Mar 2014 11:57:59 GMT Set-Cookie: session=cef14157b685078cf9c8f5d66fcefa81116a180d%7E53204bc7209fe349757896; expires=Wed, 12-Mar-2014 13:57:59 GMT; path=/; domain=.*****.com Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 <br />TXT;<br />preg_match('/(Set-Cookie:\s+session=.+?;)\s+expires=/s',$s,$m);<br />echo $m[1];

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn