解决方案 »

  1.   

    $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]);
      

  2.   

    $s=<<< TXT
    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];