我有這個隨機字符串。我只需要字符串,如mcnb8h1apihg9ffav1ubtgal77
內特定的文本,並Sat, 09-May-2015 11:49:58 GMT
提取標頭中的cookies數據
$str = 'HTTP/1.1 302 Moved Temporarily Date: Fri, 08 May 2015 11:49:58 GMT Server: Apache/2.2.22 (Debian) X-Powered-By: PHP/5.5.23-1~dotdeb.1 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: OSTSESSID=mcnb8h1apihg9ffav1ubtgal77; expires=Sat, 09-May-2015 11:49:58 GMT; Max-Age=86400; path=/support/; domain=myweb.com; secure Location: index.php Vary: Accept-Encoding Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 HTTP/1.1 200 OK Date: Fri, 08 May 2015 11:49:58 GMT Server: Apache/2.2.22 (Debian) X-Powered-By: PHP/5.5.23-1~dotdeb.1 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: OSTSESSID=sugrlug6sj8m27lrkv5id9v473; expires=Sat, 09-May-2015 11:49:58 GMT; Max-Age=86400; path=/support/; domain=myweb.com; secure Vary: Accept-Encoding Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8';
此字符串是完全隨機的。我試圖解決它:
$pattern = "#OSTSESSID=(.*); expires=(.*)\n#";
preg_match_all($pattern, $str, $matches);
print_r($matches);
但沒有奏效。請幫我解決這個問題。
有什麼理由'$ _COOKIE [ 'OSTSESSID']'是行不通的? – Machavity