欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-19 18:42:45
...
求补救匹配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;

求补救!求挽救匹配PHP字符串中的cookie
------解决方案--------------------
$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 ";
preg_match("/Set-Cookie:\s*session=[^;]+/i", $str,$match) ;
var_dump($match[0]);

------解决方案--------------------
$s=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 
TXT;
preg_match('/(Set-Cookie:\s+session=.+?;)\s+expires=/s',$s,$m);
echo $m[1];
求挽救匹配PHP字符串中的cookie

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频