1

I thought i did something smart when i serialize($userinfo) and saved the serialized data in my db... $userinfo is a plain array. but how do i get a hold of the data so my javascript can use it?

tried

var userinfo = <?=unserialize(GetUserInfo(userId));?>;

GetUserInfo is a global function that fetches the serialized string from the db.

1
  • question is unclear?? please explain, may b this [article]( gist.github.com/242617) helps u Commented May 10, 2011 at 11:08

1 Answer 1

2

Try the following:

var userinfo = <?php json_encode(GetUserInfo($user_id));?>;

JavaScript doesn't understand serialized PHP data but it does understand JSON as that is formated as a regular JavaScript object.

Sign up to request clarification or add additional context in comments.

1 Comment

Make sure to utf8 encode al the data you pass into json_encode, since it only handles utf8. On an english website you might not notice, since all un-accented latin letters are the same in iso8859-1 and utf8, but it will stop working as soon as anyone enters an "ä", "ç" or "ฒ".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.