base64 Decode into PHP Array

user2928301

I'm trying to create a web panel for a client who parses information with base64 encoding. I have set up the way to decode it, and if I echo the decoded part in the loop ($data[1]), it will write the correct information. However, I need to be able to put the information into an SQL table and perform work on it before I do that. So, I'm trying to put the data into an array, but it is acting like the array is empty for some reason.

$postData has the base64 decoded information, and it was exploded using & as the exploding agent.

$tokens = array ();
for ($i = 0; count($postData) > $i; $i++) {
    $data = explode("=", $postData[$i]);
    $tokenAdd = array();
    $tokenAdd[] = $data[1];
    array_push($tokens, $tokenAdd);
}

var_dump($tokenAdd);
Deceased

Are you shure you are dumping correct variable? Because $tokenAdd is rewritten on each iteration.

$tokens = array ();
for ($i = 0; count($postData) > $i; $i++) {
    $data = explode("=", $postData[$i]);
    // token is empty array;
    $tokenAdd = array();
    $tokenAdd[] = $data[1];
    // push array with one string element into $tokens
    array_push($tokens, $tokenAdd);
}
// dump $tokens, not $tokenAdd
var_dump($tokens);

To simplify code you may try this

$tokens = array();
foreach ($postData as $postDataItem) {
    $data = explode("=", $postDataItem);
    $tokens[] = array($data[1]);
}
var_dump($tokens); // array(array('containing'), array('some'), array('strings'))

or even more simple, if you are ok dealing not with array of array and with array of strings

$tokens = array();
foreach ($postData as $postDataItem) {
    $data = explode("=", $postDataItem);
    $tokens[] = $data[1];
}
var_dump($tokens); // array('containing', 'some', 'strings')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

base64 Decode into PHP Array

From Dev

Decode Base64 string to byte array

From Dev

Decode Base64 string to byte array

From Dev

Decode base64 string - php

From Dev

Base64 decode image PHP

From Dev

BASE64 decode and ungzip data in PHP

From Dev

Php base base64 encode and decode not working correctly

From Dev

Groovy Base64 decode vs PHP base64_decode

From Dev

Base64 decode json array sent from URL

From Dev

Base64 Failed to Decode String to Byte Array

From Dev

Decode string in base64 and load as array JS

From Dev

How to decode a base64 image and write to file using PHP

From Dev

Android Base64 decode different from javascript and PhP

From Dev

How to decode Base64 string to text in PHP?

From Dev

PHP base64 decode returns garbage characters

From Dev

c# decode base64 - Invalid length for a Base-64 char array or string

From Dev

Encoding special characters to Base64 in Javascript and decoding using base64_decode() in PHP

From Dev

base64 decode not working

From Dev

Decode base64 encoded byte array to (negative) decimal value (Java to Python)

From Dev

string base64 to integer/float/char array in php

From Dev

php string as byte array, hashed then base64 encoded

From Dev

decode base64 image data posted from android to save image on php server

From Dev

decode base64 image data posted from android to save image on php server

From Dev

Can I decode data with base64 in php which was encoded in java?

From Dev

Use PHP to Decode BASE64 encoded Signed Integers in 16bit

From Dev

Decode JSON array with PHP

From Dev

json decode with an array in php

From Dev

Base64 decode for image/jpeg;base64 in android

From Java

Decode Base64 data in Java

Related Related

HotTag

Archive