PHPDaemon\HTTPRequest\Generic::parseStr PHP Method

parseStr() public static method

Replacement for default parse_str(), it supoorts UCS-2 like this: %uXXXX
public static parseStr ( string $s, &$var, boolean $header = false ) : void
$s string String to parse
$header boolean Header-style string
return void
    public static function parseStr($s, &$var, $header = false)
    {
        static $cb;
        if ($cb === null) {
            $cb = function ($m) {
                return urlencode(html_entity_decode('&#' . hexdec($m[1]) . ';', ENT_NOQUOTES, 'utf-8'));
            };
        }
        if ($header) {
            $s = strtr($s, Generic::$hvaltr);
        }
        if (stripos($s, '%u') !== false && preg_match('~(%u[a-f\\d]{4}|%[c-f][a-f\\d](?!%[89a-f][a-f\\d]))~is', $s, $m)) {
            $s = preg_replace_callback('~%(u[a-f\\d]{4}|[a-f\\d]{2})~i', $cb, $s);
        }
        parse_str($s, $var);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * __construct
  * @param Application $appInstance [@todo description]
  * @param string $id [@todo description]
  * @param array $server [@todo description]
  * @return void
  */
 public function __construct($appInstance, $id, $server)
 {
     $this->onWrite = new StackCallbacks();
     $this->id = $id;
     $this->appInstance = $appInstance;
     $this->server = $server;
     if (isset($this->server['HTTP_COOKIE'])) {
         Generic::parseStr(strtr($this->server['HTTP_COOKIE'], Generic::$hvaltr), $this->cookie);
     }
     if (isset($this->server['QUERY_STRING'])) {
         Generic::parseStr($this->server['QUERY_STRING'], $this->get);
     }
     $this->addr = $server['REMOTE_ADDR'];
     $this->finishTimer = setTimeout(function ($timer) {
         $this->finish();
     }, $this->timeout * 1000000.0);
     $this->appInstance->subscribe('c2s:' . $this->id, [$this, 'c2s']);
     $this->appInstance->subscribe('poll:' . $this->id, [$this, 'poll'], function ($redis) {
         $this->appInstance->publish('state:' . $this->id, 'started', function ($redis) {
             // @TODO: remove this callback
         });
     });
 }
All Usage Examples Of PHPDaemon\HTTPRequest\Generic::parseStr