public static function fromString($cookie)
    {
        // Create the default return array
        $data = self::$defaults;
        // Explode the cookie string using a series of semicolons
        $pieces = array_filter(array_map('trim', explode(';', $cookie)));
        // The name of the cookie (first kvp) must include an equal sign.
        if (empty($pieces) || !strpos($pieces[0], '=')) {
            return new self($data);
        }

        // Add the cookie pieces into the parsed data array
        foreach ($pieces as $part) {

            $cookieParts = explode('=', $part, 2);
            $key = trim($cookieParts[0]);
            $value = isset($cookieParts[1])
                ? trim($cookieParts[1], " \n\r\t\0\x0B\"")
                : true;

            // Only check for non-cookies when cookies have been found
            if (empty($data['Name'])) {
                $data['Name'] = $key;
                $data['Value'] = $value;
            } else {
                foreach (array_keys(self::$defaults) as $search) {
                    if (!strcasecmp($search, $key)) {
                        $data[$search] = $value;
                        continue 2;
                    }
                }
                $data[$key] = $value;
            }
        }

        return new self($data);
    }
public static function fromString($cookie)
    {
        // Create the default return array
        $data = self::$defaults;
        // Explode the cookie string using a series of semicolons
        $pieces = array_filter(array_map('trim', explode(';', $cookie)));
        // The name of the cookie (first kvp) must include an equal sign.
        if (empty($pieces) || !strpos($pieces[0], '=')) {
            return new self($data);
        }

        // Add the cookie pieces into the parsed data array
        foreach ($pieces as $part) {

            $cookieParts = explode('=', $part, 2);
            $key = trim($cookieParts[0]);
            $value = isset($cookieParts[1])
                ? trim($cookieParts[1], " \n\r\t\0\x0B\"")
                : true;

            // Only check for non-cookies when cookies have been found
            if (empty($data['Name'])) {
                $data['Name'] = $key;
                $data['Value'] = $value;
            } else {
                foreach (array_keys(self::$defaults) as $search) {
                    if (!strcasecmp($search, $key)) {
                        $data[$search] = $value;
                        continue 2;
                    }
                }
                $data[$key] = $value;
            }
        }

        return new self($data);
    }
public static function fromString ( $ cookie ) { // Create the default return array $ data = self :: $ defaults ; // Explode the cookie string using a series of semicolons $ pieces = array_filter ( array_map ( 'trim' , explode ( ';' , $ cookie ) ) ) ; // The name of the cookie (first kvp) must include an equal sign. if ( empty ( $ pieces ) || ! strpos ( $ pieces [ 0 ] , '=' ) ) { return new self ( $ data ) ; } // Add the cookie pieces into the parsed data array foreach ( $ pieces as $ part ) { $ cookieParts = explode ( '=' , $ part , 2 ) ; $ key = trim ( $ cookieParts [ 0 ] ) ; $ value = isset ( $ cookieParts [ 1 ] ) ? trim ( $ cookieParts [ 1 ] , " \n\r\t\0\x0B\"" ) : true ; // Only check for non-cookies when cookies have been found if ( empty ( $ data [ 'Name' ] ) ) { $ data [ 'Name' ] = $ key ; $ data [ 'Value' ] = $ value ; } else { foreach ( array_keys ( self :: $ defaults ) as $ search ) { if ( ! strcasecmp ( $ search , $ key ) ) { $ data [ $ search ] = $ value ; continue 2 ; } } $ data [ $ key ] = $ value ; } } return new self ( $ data ) ; }
Create a new SetCookie object from a string

@param string $cookie Set-Cookie header string

@return self
Create a new SetCookie object from a string