Base::parse PHP Method

parse() public method

Parse string containing key-value pairs
public parse ( $str ) : array
$str string
return array
    function parse($str)
    {
        preg_match_all('/(\\w+|\\*)\\h*=\\h*(?:\\[(.+?)\\]|(.+?))(?=,|$)/', $str, $pairs, PREG_SET_ORDER);
        $out = [];
        foreach ($pairs as $pair) {
            if ($pair[2]) {
                $out[$pair[1]] = [];
                foreach (explode(',', $pair[2]) as $val) {
                    array_push($out[$pair[1]], $val);
                }
            } else {
                $out[$pair[1]] = trim($pair[3]);
            }
        }
        return $out;
    }

Usage Example

コード例 #1
0
ファイル: Module.php プロジェクト: J0s3f/simpleid
 /**
  * Obtains a SimpleID URL.  URLs produced by SimpleID should use this function.
  *
  * @param string $path the FatFree path or alias
  * @param string $query a properly encoded query string
  * @param string $secure if $relative is false, either 'https' to force an HTTPS connection, 'http' to force
  * an unencrypted HTTP connection, 'detect' to base on the current connection, or NULL to vary based on SIMPLEID_BASE_URL
  * @return string the url
  *
  * @since 0.7
  */
 public function getCanonicalURL($path = '', $query = '', $secure = null)
 {
     $config = $this->f3->get('config');
     $canonical_base_path = $config['canonical_base_path'];
     if (preg_match('/^(?:@(\\w+)(?:(\\(.+?)\\))*|https?:\\/\\/)/', $path, $parts)) {
         if (isset($parts[1])) {
             $aliases = $this->f3->get('ALIASES');
             if (!empty($aliases[$parts[1]])) {
                 $path = $aliases[$parts[1]];
                 $path = $this->f3->build($path, isset($parts[2]) ? $this->f3->parse($parts[2]) : array());
                 $path = ltrim($path, '/');
             }
         }
     }
     // Make sure that the base has a trailing slash
     if (substr($config['canonical_base_path'], -1) == '/') {
         $url = $config['canonical_base_path'];
     } else {
         $url = $config['canonical_base_path'] . '/';
     }
     if ($secure == 'https' && stripos($url, 'http:') === 0) {
         $url = 'https:' . substr($url, 5);
     }
     if ($secure == 'http' && stripos($url, 'https:') === 0) {
         $url = 'http:' . substr($url, 6);
     }
     if ($secure == 'detect' && $this->isHttps() && stripos($url, 'http:') === 0) {
         $url = 'https:' . substr($url, 5);
     }
     if ($secure == 'detect' && !$this->isHttps() && stripos($url, 'https:') === 0) {
         $url = 'http:' . substr($url, 6);
     }
     $url .= $path . ($query == '' ? '' : '?' . $query);
     return $url;
 }
All Usage Examples Of Base::parse