PHP 文字列は次のとおりです:
HTTP/1.1 200 OK 日付: Wed, 12 Mar 2014 11:57:58 GMT サーバー: Apache/2.2.9 (APMServ) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/ 5.2。 6 7E53204bc7209fe349757896; 有効期限=2014 年 3 月 12 日水曜日 13:57:59 GMT; ドメイン = .*****.com Transfer-Encoding: chunked Content-Type: text/html- 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 ";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];