Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 264757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:42:44+00:00 2026-05-11T22:42:44+00:00

Is there any way that I could enjoy a decodeValue() function in PHP, too?

  • 0

Is there any way that I could enjoy a decodeValue() function in PHP, too? I am posting those encodedValue values to a PHP file and I need to work with them in PHP as an array.

How can I end up with a PHP array or something from the encoded state in Ext? Or, is there any other way that I could work the encoded values to be able to easily read them in PHP? Here is the function code:

decodeValue : function(cookie){
        var re = /^(a|n|d|b|s|o)\:(.*)$/;
        var matches = re.exec(unescape(cookie));
        if(!matches || !matches[1]) return; // non state cookie
        var type = matches[1];
        var v = matches[2];
        switch(type){
            case "n":
                return parseFloat(v);
            case "d":
                return new Date(Date.parse(v));
            case "b":
                return (v == "1");
            case "a":
                var all = [];
                var values = v.split("^");
                for(var i = 0, len = values.length; i < len; i++){
                    all.push(this.decodeValue(values[i]));
                }
                return all;
           case "o":
                var all = {};
                var values = v.split("^");
                for(var i = 0, len = values.length; i < len; i++){
                    var kv = values[i].split("=");
                    all[kv[0]] = this.decodeValue(kv[1]);
                }
                return all;
           default:
                return v;
        }
    }

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:42:44+00:00Added an answer on May 11, 2026 at 10:42 pm

    Below is my port to PHP. I used the DateTime class in lieu of Date as it is the closest PHP equivalent, but you could also use strftime() to get a Unix timestamp, or whatever method you prefer. Also, for type ‘o’ I return an array rather than an object, keyed by the object’s parameter names.

    Here’s the code:

    function decodeValue($cookie) {
        $cookie = urldecode($cookie);
        $re = '/^(a|n|d|b|s|o)\:(.*)$/';
        $matches = array();
        preg_match($re, $cookie, $matches);
        if(!$matches || !$matches[1]) return; // non state cookie
        $type = $matches[1];
        $v = $matches[2];
        switch ($type){
            case "n":
                return floatval($v);
            case "d":
                return new DateTime($v);
            case "b":
                return ($v == "1" ? true : false);
            case "a":
                $all = array();
                $values = explode('^', $v);
                $len = count($values);
                for ($i = 0; $i < $len; $i++) {
                    $all.push(decodeValue($values[$i]));
                }
                return $all;
           case "o":
                $all = array();
                $values = explode('^', $v);
                $len = count($values);
                for($i = 0; $i < $len; $i++){
                    $kv = explode('=', $values[$i]);
                    $all[$kv[0]] = decodeValue($kv[1]);
                }
                return $all;
           default:
                return $v;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For Objective-C methods, the general practice is to put methods… May 11, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer I've found a workoutaround for this problem :) . I've… May 11, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer You can only populate your Response, the Request is input… May 11, 2026 at 11:44 pm

Related Questions

Is there any way that I could get the source of a website (as
Is there any way that I can find the container pointed to by an
Suppose I have two applications written in C#. The first is a third party
I am not entirely sure if this is possible or not but so far
I have a Flex application where I'm using a Canvas to contain several other

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.