Matching the cookie in the PHP string

Source: Internet
Author: User
Find a remedy to match the cookie in the PHP string. Below is a PHP string:
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-: PHP/5.2.6 Cache-Control: public, max-age = 10 Last-Modified: Wed, 12 Mar 2014 11:57:59 GMT Set-Cookie: session = sessions % 7E53204bc7209fe349757896; expires = Wed, 12-Mar-2014 13:57:59 GMT; path =/; domain =. *****. com Transfer-Encoding: chunked Content-Type: text/html; charset = utf-8

I want to use the php regular expression to match this string:
Set-Cookie: session = cef14157b685078cf9c8f5d66fcefa81116a180d % 7E53204bc7209fe349757896;

Remedy!


Reply to discussion (solution)

$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=<<< TXTHTTP/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];

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.