【发布时间】:2015-05-08 12:08:33
【问题描述】:
我有这个随机字符串。我只需要字符串中的特定文本,例如mcnb8h1apihg9ffav1ubtgal77 和Sat, 09-May-2015 11:49:58 GMT
$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']不起作用的任何原因?
标签: php regex cookies http-headers preg-match-all