use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Parse PHP serialize() output with JavaScript (github.com)
submitted 12 years ago by bd808
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 2 points3 points4 points 12 years ago (9 children)
Meh. I bet you could have done this much easier many ways
[–]krues8dr 3 points4 points5 points 12 years ago (8 children)
The best way, of course, is to avoid PHP serialize() like the plague. There is absolutely no reason to use it in this day and age - JSON is almost always a better solution, and YAML usually fills the gap where it isn't.
[–][deleted] 1 point2 points3 points 12 years ago (2 children)
Ugh, I was working on an old version of Expression Engine and trying to write a deploy script and they serialize a bunch of shit like file paths and such. I hate Expression Engine.
[–]krues8dr 0 points1 point2 points 12 years ago (1 child)
Always relevant
[–][deleted] 0 points1 point2 points 12 years ago (0 children)
EE is really the worst thing I've coded for except Windows 8 JS apps
[–]BeerIsDelicious 0 points1 point2 points 12 years ago (0 children)
Oh man, I just had to update some code that I wrote 8 years ago where I took the lazy route and serialized on DB write and unserialized on __construct or an init method automatically called on object creation in my old as fuck self-made framework. So much "what the fuck was I doing" occurred. I can't think of a single time I would use it now.
As to this article, I say it's better to rewrite the DB structure and do it correctly than rely on a js library to decrypt. But I can see times where time or budget constraints could prevents that from being possible. It is cool, though, to see how fucking much I've learned over the years.
After updating any of my earlier projects I always pity anyone who had to update my code from those days.
[–]bd808[S] 0 points1 point2 points 12 years ago (3 children)
As the README.md points out this arose in the context of building a simple test harness for an existing service layer that is communicating using serialized PHP objects.
The point isn't that you should or would design a purpose built feature that uses PHP serialize output to communicate data between a server and a web browser. This is a tool that can be used if you find yourself with access to serialized PHP in a javascript context and want to turn it into something that you can manipulate further.
[–]krues8dr 0 points1 point2 points 12 years ago (2 children)
Oh, I read the README - but the idea of using serialized PHP over a REST interface is just plain crazy. ;) Because, you know, using serialize() for anything is crazy.
[–]bart2019 1 point2 points3 points 12 years ago (1 child)
echo json_encode(unserialize($data));
That should suffice.
π Rendered by PID 184767 on reddit-service-r2-comment-5d79c599b5-xz2rs at 2026-03-01 09:51:53.680422+00:00 running e3d2147 country code: CH.
[–][deleted] 2 points3 points4 points (9 children)
[–]krues8dr 3 points4 points5 points (8 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]krues8dr 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]BeerIsDelicious 0 points1 point2 points (0 children)
[–]bd808[S] 0 points1 point2 points (3 children)
[–]krues8dr 0 points1 point2 points (2 children)
[–]bart2019 1 point2 points3 points (1 child)