Forum Moderators: coopster

Message Too Old, No Replies

encoding an array?

         

ahmedtheking

11:02 pm on May 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've tried many a time to encode an array through base64_encode(), but it just can't be done! Am I doing something wrong or what?

ironik

11:12 pm on May 17, 2005 (gmt 0)

10+ Year Member



try:

$myArray = array('1','2','3');
$serialized = serialize($myArray);
$encoded = base64_encode();

Then to restore it use base64_decode() and unserialize.

Is that what you were trying to achieve, or were you looking to base64_encode each element in the array? If you were, probably the best way is to use array_walk().

ahmedtheking

9:24 am on May 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What I was trying to do was to pass arrayed values into the URL. I couldn't encode them, so I had to implode them with a common seperator, usually a *, and then base64 them!

ironik

5:52 am on May 19, 2005 (gmt 0)

10+ Year Member



definitely serialize them then if you want to retain the array structure. You can serialize and then htmlentities() or base64_encode() them to make it safe for the URL.

Maybe instead of passing them through the URL you could pass them through session variables. It would take away the problem of 'ultra' huge URLS.