2017-12-22 2 views
0

Ich speichere Formularelemente als serialisierte Daten in einem Cookie.Decodiere serialisierte Cookie- und Loop-Optionen

Auf einer anderen Seite Ich möchte dieses Cookie sammeln, aber das Cookie enthält diese Zeichenfolge:

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 und% 5D sind Klammern ich dachte, aber wie kann ich alle diese Optionen in der Zeichenfolge schauen und Holen Sie ihren ID + -Wert in ein Array mit PHP.

So von oben Saite würde Ich mag mit ein Array erstellen:

arr = array (

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

); 
+0

Dank mich wissen zu lassen. Ich habe die Antwort akzeptiert. – Senta

Antwort

1

Ich denke, was Sie wollen, ist 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. 

Siehe Ausführung here:

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

    [productId] => 59891 
)