Skip to content

Instantly share code, notes, and snippets.

@hasibomi
Created November 20, 2016 09:32
Show Gist options
  • Save hasibomi/c5a4f736c6d0d5fa0d953754a84f5b65 to your computer and use it in GitHub Desktop.
Save hasibomi/c5a4f736c6d0d5fa0d953754a84f5b65 to your computer and use it in GitHub Desktop.
Unserialize php's serialized array in javascript.
function unserialize(array) {
var accumulated_array = [];
for (var j = 0; j < array.split('{')[1].split(';').length; j++) {
var sp = array.split('{')[1].split(';');
var np = sp[j].split(':');
for (var k = 0; k < np.length; k++) {
if (k != 0 && k % 2 == 0) {
if (np[k] == '"http' || np[k] == '"https') {
var spl = np[k] + ':' + np[k+1];
spl = spl.split('"')[1];
accumulated_array.push(spl);
} else {
accumulated_array.push(np[k].split('"')[1]);
}
}
}
}
return accumulated_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment