if (!function_exists('ckStr2ckArr')) {
function ckStr2ckArr($cookieValue,$key='')
{
if(empty($cookieValue)) return [];
// 第一步:将 cookie 字符串拆分为键值对数组
$cookiePairs = explode(';', $cookieValue);
// 创建一个关联数组来存储键值对
$cookieArray = [];
foreach ($cookiePairs as $pair) {
$pair = trim($pair); // 去除多余的空格
if ($pair) {
list($k, $value) = explode('=', $pair, 2);
$cookieArray[$k] = $value;
}
}
//取指定的key值
if(!empty($key)) return $cookieArray[$key];
//取所有数组
return $cookieArray;
}
}
$str = 'cna=Z10vHxyLLhkCAXPgqFaTMN9A; t=0dfd9e12691b5e686d8e406981bc179f; cookie2=113f243906b3776465e8fc246291d43d; xlly_s=1; _samesite_flag_=true; _tb_token_=548dd75bd1b39; unb=2209368547703; _hvn_lgc_=77; mtop_partitioned_detect=1; _m_h5_tk=518ab9b7ade30d1634c92f423962eb36_1729138819303; _m_h5_tk_enc=548aa63b41127caaeb4e9bc65e796a49; sdkSilent=1729216940928; sgcookie=E100MANykuWklerydA%2BMl9VIKBDu93fi6%2FAkc52GgwunEqZm9s%2F4QR3w70efJdK0OjoqaSSsURjd8rmp0UbOxRuxqtfyCuinoz28cswnbcjUUfk%3D; csg=96db0be1; havana_lgc2_77=eyJoaWQiOjIyMDkzNjg1NDc3MDMsInNnIjoiM2I1OTA0MDEzYTljZTcwZTRkZDkwYTQ1YzkzYjgxYzEiLCJzaXRlIjo3NywidG9rZW4iOiIxcEprcmNFY3FXa3l3U1RnY2hhT1U0dyJ9; havana_lgc_exp=1731722711974; isg=BHd3EOiN3F5lmFlq1jMGY7UyBm3BPEuetKiDGckl5cateJK60QzK7iOTWtgmkCMW; tfstk=gtErVp23SDVj2CSshxnEQC-n2_n-D0f1tkGIKJ2nFbcoAahntJFxdHw3VWPU_7-7OJf8TklmM2aWVWNeT7NjZ3wSNSl31SZI-6n7gSa0k_C-O8MUGr4Aw_EUpHk3KWB-OTQbe8nKx11_YGw8eWEySDXjrIXnLv1_7crXm8nKx19XxNsae50nOCBExtomdYJox2cl3jDsi3DHqvAc3vhmx30nrqAmevkk-vV3ntkKiXDL382H0AglCB0NDGfWA4cgEj-HbdHrrewWRh-a0Yuzx8cVL9rqU4lilG5xelygElHUvOYETzzuNxFFbso0gy2nuo1kfXaaCk3Uq9pS9zMtqYPhjFG0u-q-5-pPI-ija-DTu1--VRz0VqEGG3FUC7rE57scEWnoKW3TA1K-ZJ2TXPiNYFogg-qt-kCvvXabKko8sst492jrHBHmRXqLzBYnrxHq1tW4O4UiIC35k2YpJqmt3f6SFeLKrWMq1TgBJe3mtxl1Fw5..';
//转换数组
$arr = ckStr2ckArr($newStr);
dump($arr);
//取数组中某一个值
$arr = ckStr2ckArr($newStr,'cookie2');
dump($arr);die;