2017-12-22 1 views
0

폼 요소를 일련 화 된 데이터로 쿠키에 저장합니다.직렬화 된 쿠키 및 루프 옵션 디코드

나는이 쿠키를 수집 할 다른 페이지에서

하지만 쿠키는이 문자열을 포함

form_key=kcE3W2vzParNhPN5&options%5B1508%5D=2025&options%5B1509%5D=1234&options%5B1510%5D=5678&options%5B1511%5D=&options%5B1512%5D=&options%5B1513%5D=&productId=59891 

%의 5B와 % 5D 내가 생각 브래킷,하지만 난 문자열에있는 모든 옵션을 통해 방법을 볼 수 있으며, 그들의 ID + 값을 PHP로 배열로 가져와라. 그래서 위의 문자열에서

내가 가진 배열을 만들 싶습니다 : 당신이 원하는 내가 생각

arr = array (

[1508] = '2025'; 
[1509] = '1234'; 
[1510] = '5678'; 
[1511] = ''; 
[1512] = ''; 

); 
+0

감사합니다 내게 알려주기 위해서. 나는 그 대답을 받아 들였다. – Senta

답변

1

parse_str()입니다 :

$str = "form_key=kcE3W2vzParNhPN5&options%5B1508%5D=2025&options%5B1509%5D=1234&options%5B1510%5D=5678&options%5B1511%5D=&options%5B1512%5D=&options%5B1513%5D=&productId=59891"; 

$output = array(); 
parse_str($str, $output); 

print_r($output); // $output['options'] will contain your array you're looking for. 

참조 실행 here :

Array 
(
    [form_key] => kcE3W2vzParNhPN5 
    [options] => Array 
     (
      [1508] => 2025 
      [1509] => 1234 
      [1510] => 5678 
      [1511] => 
      [1512] => 
      [1513] => 
     ) 

    [productId] => 59891 
)