I ran to this issue and wanted a solution and this wasn't 100% right for me because if the string was like $str = "mine'this , the appostrophe would cause a problem. so I came up with a litle trick :
$stick='';
$cook = explode($str,$cookie,2);
foreach($cook as $c){
if(preg_match("/^'/", $c)||preg_match('/^"/', $c)){
//we have 's dsf fds... so we need to find the first |sess| because it is the delimiter'
$stick = '|sess|'.explode('|sess|',$c,2)[1];
}else{
$stick = $c;
}
$cookies.=$stick;
}