RegEx Help - Not parsing like it should
Posted: Wed Jan 17, 2007 10:38 pm
Here is my code:
Basically I am parsing cookies from an HTTP header. It works pretty good except that the RegEx is parsing more than it should. Here is the output when printing the cookies array:
Cheers,
- Josh
Code: Select all
private function parse_cookies()
{
$lines = split($this->newline, $this->header);
foreach ($lines as $line)
{
if (preg_match("/Set-Cookie\: (.*)=(.*)\;/", $line, $matches))
{
$this->cookies[$matches[1]] = $matches[2];
}
}
}Basically what it's doing is skipping the ";" and grabbing the rest of the line. Take the first line for example, it's "neodebug=deleted; expires", as you can see there is a ";" there but in my RegEx I wanted it to stop at the ";" and only grab the things before it but as seen here it's just completely skipping it. Is there a reason for this? Thanks.neodebug=deleted; expires=Wed, 18-Jan-06 04:33:13 GMT; path = /
nupi=0; expires=Thu, 18-Jan-07 02:53:14 GMT; path = /
nupid=0; expires=Thu, 18-Jan-07 02:53:14 GMT; path = /
npid=0; expires=Thu, 18-Jan-07 02:53:14 GMT; path = /
np_uniq=pending; expires=Fri, 18-Jan-08 04:33:14 GMT; path = /
xt6Yr4e33D=59182809479467180131245; expires=Fri, 18-Jan-08 04:33:14 GMT; path = /
Cheers,
- Josh