Twitter_OAuthUtil::parse_parameters PHP Méthode

parse_parameters() public static méthode

['a' => array('b','c'), 'd' => 'e']
public static parse_parameters ( $input )
    public static function parse_parameters($input)
    {
        if (!isset($input) || !$input) {
            return [];
        }
        $pairs = explode('&', $input);
        $parsed_parameters = [];
        foreach ($pairs as $pair) {
            $split = explode('=', $pair, 2);
            $parameter = Twitter_OAuthUtil::urldecode_rfc3986($split[0]);
            $value = isset($split[1]) ? Twitter_OAuthUtil::urldecode_rfc3986($split[1]) : '';
            if (isset($parsed_parameters[$parameter])) {
                // We have already recieved parameter(s) with this name, so add to the list
                // of parameters with this name
                if (is_scalar($parsed_parameters[$parameter])) {
                    // This is the first duplicate, so transform scalar (string) into an array
                    // so we can add the duplicates
                    $parsed_parameters[$parameter] = [$parsed_parameters[$parameter]];
                }
                $parsed_parameters[$parameter][] = $value;
            } else {
                $parsed_parameters[$parameter] = $value;
            }
        }
        return $parsed_parameters;
    }

Usage Example

 /**
  * Get 'enduring' access token and secret
  * @param string, token returned by Twitter
  * @return associative array with keys: oauth_token, oauth_token_secret, screen_name
  *   or error message string
  */
 public function getAuthority($verifier)
 {
     try {
         $results = $this->request('https://api.twitter.com/oauth/access_token', 'POST', array('oauth_verifier' => $verifier));
     } catch (TwitterException $e) {
         return $e->getMessage();
     }
     if ($results) {
         $token = Twitter_OAuthUtil::parse_parameters($results);
         if (is_array($token) && isset($token['oauth_token'])) {
             unset($token['user_id']);
             return $token;
         }
     }
     return 'Twitter authority-request failed';
 }
All Usage Examples Of Twitter_OAuthUtil::parse_parameters