Reputation: 49
i have problem, when POST informations in URL without encode it all is fine and i can use foreach for all informations because i got it as array
but when use GET and decode it, informations convert from array to string and can't use foreach anymore, (i try encode it again as json but i fail).
i have base64 value in URL like this
http://www.test.com/index.php?info=dXNlcm5hbWU9PmJyb29rcwpjb2xvcj0+Ymx1ZQp1cmw9Pmh0dHA6Ly93d3cudGVzdC5jb20vNDE0Mg==
i use $info = base64_decode($_GET['info']);
to get it and decode
i want foeach it inside li like this echo <li>$info_key is $info_value</li>
NOTE: when decode it you will see i'm using => between key and value, and use return line for each array, maybe i can use PHP_EOL to split or collect
Another NOTE: i don't know how much values will get from url so because that i need to use foreach to loop all collected values
Thank you stackoverflow community ✌
Upvotes: 0
Views: 579
Reputation: 46610
Once decoded your string looks like:
username=>brooks
color=>blue
url=>http://www.test.com/4142
foreach
is for looping over iterables, so you would need to parse it into an array.
<?php
$str = base64_decode('dXNlcm5hbWU9PmJyb29rcwpjb2xvcj0+Ymx1ZQp1cmw9Pmh0dHA6Ly93d3cudGVzdC5jb20vNDE0Mg==');
$lines = explode(PHP_EOL, $str);
foreach ($lines as $line) {
$line = explode('=>', $line);
echo '<li>'.$line[0].' is '.$line[1].'</li>'.PHP_EOL;
}
<li>username is brooks</li>
<li>color is blue</li>
<li>url is http://www.test.com/4142</li>
Though you should just avoid what you're doing and pass them as parameters.
Upvotes: 1