Created
November 20, 2016 09:32
-
-
Save hasibomi/c5a4f736c6d0d5fa0d953754a84f5b65 to your computer and use it in GitHub Desktop.
Unserialize php's serialized array in javascript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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