在Curl中我们有些时候需要将cookies字符串转换为数组,可以用下面的方法
public function setCookieString($string)
{
$result = array();
if(preg_match_all('/\s*([^;=]+)=([^;]+)/i',$string,$matches) > 0){
if(isset($matches[1]) && isset($matches[2])){
if(count($matches[1]) == count($matches[2])){
foreach ($matches[1] as $handle => $key) {
$result[$key] = $matches[2][$handle];
}
}
}
}
return $result;
}
参数只能放cookies字符串,如下图绿色框的部分
tmc=1.170236450.59236819.1462889961066.1462889961066.1462889961066; tma=170236450.72078710.1438771475412.1449463856228.1449536313927.12; tmd=202.170236450.72078710.1438771475412.
