Costinu’s Blog

When you dream, there are no rules. People can fly; anything can happen. Sometimes, there’s a moment as you’re waking, and you become aware of the real world around you; but you’re still dreaming. You may think you can fly, but you better not try.
Oct 5
JavaScript:
  1. /**
  2. *function implementing PHP's serialize() function
  3. *@param: v - elements to be serialized
  4. *@return: serialized string
  5. */
  6. function serialize(v){
  7. if(typeof(v)=='object' && v.constructor==Array){
  8. var i,s='',c=0;
  9. for(i in v){
  10. ++c;
  11. s+=serialize(i)+serialize(v[i]);
  12. }
  13. s="a:"+c+":{"+s+"}";
  14. return s;
  15. } else {
  16. if(Number(v)==v){
  17. return 'i:'+v+';';
  18. } else
  19. if(typeof(v)=='string'){
  20. return 's:'+v.length+':"'+v+'";';
  21. }
  22. }
  23. }

Bookmark and Share:

Nici un comentariu. »

Nici un comentariu până acum.

Feed RSS pentru acest articol. TrackBack URI

Adaugă un comentariu


Comments links could be nofollow free.