This does it without regexps, but requires the PECL HTTP extension.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
curl_close($ch);
$headers = http_parse_headers($result);
$cookobjs = Array();
foreach($headers AS $k => $v){
if (strtolower($k)=="set-cookie"){
foreach($v AS $k2 => $v2){
$cookobjs[] = http_parse_cookie($v2);
}
}
}
$cookies = Array();
foreach($cookobjs AS $row){
$cookies[] = $row->cookies;
}
$tmp = Array();
// sort k=>v format
foreach($cookies AS $v){
foreach ($v AS $k1 => $v1){
$tmp[$k1]=$v1;
}
}
$cookies = $tmp;
print_r($cookies);