本文整理汇总了PHP中parse_str函数的典型用法代码示例。如果您正苦于以下问题:PHP parse_str函数的具体用法?PHP parse_str怎么用?PHP parse_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param mixed $in
*/
public function __construct($in = null)
{
$fields = array('to', 'cc', 'bcc', 'message', 'body', 'subject');
if (is_string($in)) {
if (($pos = strpos($in, '?')) !== false) {
parse_str(substr($in, $pos + 1), $this->args);
$this->args['to'] = substr($in, 0, $pos);
} else {
$this->args['to'] = $in;
}
} elseif ($in instanceof Horde_Variables) {
foreach ($fields as $val) {
if (isset($in->{$val})) {
$this->args[$val] = $in->{$val};
}
}
} elseif (is_array($in)) {
$this->args = $in;
}
if (isset($this->args['to']) && strpos($this->args['to'], 'mailto:') === 0) {
$mailto = @parse_url($this->args['to']);
if (is_array($mailto)) {
$this->args['to'] = isset($mailto['path']) ? $mailto['path'] : '';
if (!empty($mailto['query'])) {
parse_str($mailto['query'], $vals);
foreach ($fields as $val) {
if (isset($vals[$val])) {
$this->args[$val] = $vals[$val];
}
}
}
}
}
}
示例2: _configureViaDSN
protected function _configureViaDSN($dsn)
{
$dsnVars = array();
if (strpos($dsn, '=') === false) {
throw new Zend_Tool_Project_Provider_Exception('At least one name value pair is expected, typcially ' . 'in the format of "adapter=Mysqli&username=uname&password=mypass&dbname=mydb"');
}
parse_str($dsn, $dsnVars);
// parse_str suffers when magic_quotes is enabled
if (get_magic_quotes_gpc()) {
array_walk_recursive($dsnVars, array($this, '_cleanMagicQuotesInValues'));
}
$dbConfigValues = array('resources' => array('db' => null));
if (isset($dsnVars['adapter'])) {
$dbConfigValues['resources']['db']['adapter'] = $dsnVars['adapter'];
unset($dsnVars['adapter']);
}
$dbConfigValues['resources']['db']['params'] = $dsnVars;
$isPretend = $this->_registry->getRequest()->isPretend();
// get the config resource
$applicationConfig = $this->_loadedProfile->search('ApplicationConfigFile');
$applicationConfig->addItem($dbConfigValues, $this->_sectionName, null);
$response = $this->_registry->getResponse();
if ($isPretend) {
$response->appendContent('A db configuration for the ' . $this->_sectionName . ' section would be written to the application config file with the following contents: ');
$response->appendContent($applicationConfig->getContents());
} else {
$applicationConfig->create();
$response->appendContent('A db configuration for the ' . $this->_sectionName . ' section has been written to the application config file.');
}
}
示例3: testRevokeAccess
public function testRevokeAccess()
{
$accessToken = "ACCESS_TOKEN";
$refreshToken = "REFRESH_TOKEN";
$accessToken2 = "ACCESS_TOKEN_2";
$token = "";
$client = $this->getClient();
$response = $this->getMock("Google_Http_Request", array(), array(''));
$response->expects($this->any())->method('getResponseHttpCode')->will($this->returnValue(200));
$io = $this->getMock("Google_IO_Stream", array(), array($client));
$io->expects($this->any())->method('makeRequest')->will($this->returnCallback(function ($request) use(&$token, $response) {
$elements = array();
parse_str($request->getPostBody(), $elements);
$token = isset($elements['token']) ? $elements['token'] : null;
return $response;
}));
$client->setIo($io);
// Test with access token.
$oauth = new Google_Auth_OAuth2($client);
$oauth->setAccessToken(json_encode(array('access_token' => $accessToken, 'created' => time(), 'expires_in' => '3600')));
$this->assertTrue($oauth->revokeToken());
$this->assertEquals($accessToken, $token);
// Test with refresh token.
$oauth = new Google_Auth_OAuth2($client);
$oauth->setAccessToken(json_encode(array('access_token' => $accessToken, 'refresh_token' => $refreshToken, 'created' => time(), 'expires_in' => '3600')));
$this->assertTrue($oauth->revokeToken());
$this->assertEquals($refreshToken, $token);
// Test with passed in token.
$this->assertTrue($oauth->revokeToken($accessToken2));
$this->assertEquals($accessToken2, $token);
}
示例4: process_call
/**
* @inheritdoc
*
* @param array $arguments
*/
public function process_call($arguments)
{
$am = $this->get_am();
$am->ajax_begin(array('nonce' => $am->get_action_js_name(Types_Ajax::CALLBACK_SETTINGS_ACTION)));
$setting = sanitize_text_field(wpcf_getpost('setting'));
$setting_value = wpcf_getpost('setting_value');
if (!is_array($setting_value)) {
parse_str($setting_value, $setting_value);
$setting_value = array_pop($setting_value);
}
$sanitized_value = array();
foreach ($setting_value as $key => $value) {
$sanitized_key = sanitize_title($key);
$sanitized_value[$sanitized_key] = sanitize_text_field($value);
}
// use toolset settings if available
if (class_exists('Toolset_Settings') && method_exists('Toolset_Settings', 'get_instance')) {
$toolset_settings = Toolset_Settings::get_instance();
if (method_exists($toolset_settings, 'save')) {
$toolset_settings[$setting] = $sanitized_value;
$toolset_settings->save();
$am->ajax_finish('success', true);
}
} else {
update_option($setting, $sanitized_value);
$am->ajax_finish('success', true);
}
// default toolset setting error will be used
// todo throw specific error
$am->ajax_finish(array('error'), false);
}
示例5: prepareExtract
public function prepareExtract()
{
$request_uri = isset($_GET['REQUEST_URI']) ? $_GET['REQUEST_URI'] : (isset($_POST['REQUEST_URI']) ? $_POST['REQUEST_URI'] : (isset($_ENV['REQUEST_URI']) ? $_ENV['REQUEST_URI'] : getenv("REQUEST_URI")));
if (substr($request_uri, 0, 1) != "/") {
$request_uri = "/" . $request_uri;
}
$request_uri = trim($request_uri);
$url = "http" . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? "s" : "") . "://" . getenv("HTTP_HOST") . $request_uri;
// parse entire url
$parsed_url = @parse_url($url);
// validate query parameter
if (is_array($parsed_url) && array_key_exists('query', $parsed_url) && $parsed_url['query']) {
$parsed_query_arr = null;
parse_str($parsed_url['query'], $parsed_query_arr);
$_GET = $parsed_query_arr ? $parsed_query_arr : array();
}
// superglobal arrays
$superglobals = array("_COOKIE" => $_COOKIE, "_GET" => $_GET, "_POST" => $_POST, "_FILES" => $_FILES, "_ENV" => $_ENV, "_SERVER" => $_SERVER);
// set default
// merge superglobals arrays
foreach ($superglobals as $key => $super_array) {
// set internal data from superglobal arrays
$this->{$key} = self::prepareSuperglobal($super_array);
}
return false;
}
示例6: parseRequest
/**
* Parse the incoming request in a RESTful way
*
* @param \PASL\Web\Service\Request The request object
*/
public function parseRequest($oRequest)
{
$oRequestData = array();
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
$oRequestHash = $_REQUEST;
break;
case 'POST':
$oRequestHash = $_REQUEST;
break;
case 'PUT':
parse_str(file_get_contents("php://input"), $oRequestHash);
break;
}
foreach ($oRequestHash as $val) {
if (trim($val) != "" && !is_null($val)) {
array_push($oRequest->oRequestHash, $val);
}
}
$oRequest->requestPayload = $oRequestData;
$oRequest->method = $oRequest->oRequestHash[2];
// Grab the method arguments
$methodArgs = $oRequest->oRequestHash;
array_shift($methodArgs);
array_shift($methodArgs);
array_shift($methodArgs);
$oRequest->methodArgs = $methodArgs;
return $oRequest;
}
示例7: __construct
/**
* @param array $vars An associative array with the following optional values:
* @param array 'urlParams' the parameters which were matched from the URL
* @param array 'get' the $_GET array
* @param array|string 'post' the $_POST array or JSON string
* @param array 'files' the $_FILES array
* @param array 'server' the $_SERVER array
* @param array 'env' the $_ENV array
* @param array 'cookies' the $_COOKIE array
* @param string 'method' the request method (GET, POST etc)
* @param string|false 'requesttoken' the requesttoken or false when not available
* @see http://www.php.net/manual/en/reserved.variables.php
*/
public function __construct(array $vars = array(), $stream = 'php://input')
{
$this->inputStream = $stream;
$this->items['params'] = array();
if (!array_key_exists('method', $vars)) {
$vars['method'] = 'GET';
}
foreach ($this->allowedKeys as $name) {
$this->items[$name] = isset($vars[$name]) ? $vars[$name] : array();
}
// 'application/json' must be decoded manually.
if (strpos($this->getHeader('Content-Type'), 'application/json') !== false) {
$params = json_decode(file_get_contents($this->inputStream), true);
if (count($params) > 0) {
$this->items['params'] = $params;
if ($vars['method'] === 'POST') {
$this->items['post'] = $params;
}
}
// Handle application/x-www-form-urlencoded for methods other than GET
// or post correctly
} elseif ($vars['method'] !== 'GET' && $vars['method'] !== 'POST' && strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') !== false) {
parse_str(file_get_contents($this->inputStream), $params);
if (is_array($params)) {
$this->items['params'] = $params;
}
}
$this->items['parameters'] = array_merge($this->items['get'], $this->items['post'], $this->items['urlParams'], $this->items['params']);
}
示例8: finalStep
public function finalStep(&$state)
{
SimpleSAML_Logger::debug("oauth wrap: Using this verification code [" . $state['authwindowslive:wrap_verification_code'] . "]");
// Retrieve Access Token
// Documentation at: http://msdn.microsoft.com/en-us/library/ff749686.aspx
$postData = 'wrap_client_id=' . urlencode($this->key) . '&wrap_client_secret=' . urlencode($this->secret) . '&wrap_callback=' . urlencode(SimpleSAML_Module::getModuleUrl('authwindowslive') . '/linkback.php') . '&wrap_verification_code=' . urlencode($state['authwindowslive:wrap_verification_code']);
$context = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postData));
$result = \SimpleSAML\Utils\HTTP::fetch('https://consent.live.com/AccessToken.aspx', $context);
parse_str($result, $response);
// error checking of $response to make sure we can proceed
if (!array_key_exists('wrap_access_token', $response)) {
throw new Exception('[' . $response['error_code'] . '] ' . $response['wrap_error_reason'] . "\r\nNo wrap_access_token returned - cannot proceed\r\n" . $response['internal_info']);
}
SimpleSAML_Logger::debug("Got an access token from the OAuth WRAP service provider [" . $response['wrap_access_token'] . "] for user [" . $response['uid'] . "]");
// Documentation at: http://msdn.microsoft.com/en-us/library/ff751708.aspx
$opts = array('http' => array('header' => "Accept: application/json\r\nAuthorization: WRAP access_token=" . $response['wrap_access_token'] . "\r\n"));
$data = \SimpleSAML\Utils\HTTP::fetch('https://apis.live.net/V4.1/cid-' . $response['uid'] . '/Profiles', $opts);
$userdata = json_decode($data, TRUE);
$attributes = array();
$attributes['windowslive_uid'] = array($response['uid']);
$attributes['windowslive_targetedID'] = array('http://windowslive.com!' . $response['uid']);
$attributes['windowslive_user'] = array($response['uid'] . '@windowslive.com');
if (array_key_exists('Entries', $userdata)) {
foreach ($userdata['Entries'][0] as $key => $value) {
if (is_string($value)) {
$attributes['windowslive.' . $key] = array((string) $value);
}
}
if (array_key_exists('Emails', $userdata['Entries'][0])) {
$attributes['windowslive_mail'] = array($userdata['Entries'][0]['Emails'][0]['Address']);
}
}
SimpleSAML_Logger::debug('LiveID Returned Attributes: ' . implode(", ", array_keys($attributes)));
$state['Attributes'] = $attributes;
}
示例9: resolve
/**
* Resolve content meta data.
*
* @param array $content Original user provided content data
* @return array $content Content data with additionaly retrieved meta data
* @author Niklas Lindblad
*/
public function resolve($content)
{
/**
* Video ID is given by the 'v' URL parameter.
*
* @author Niklas Lindblad
*/
parse_str(parse_url($content['url'], PHP_URL_QUERY), $output);
$query = sprintf('http://gdata.youtube.com/feeds/api/videos?q=%s&max-results=1&v=2&alt=jsonc', $output['v']);
$data = @json_decode(@file_get_contents($query), true);
if (!$data) {
throw new Exception('Could not retrieve meta data.');
}
/**
* Since we search for a unique ID, the first
* result is always the one we want.
*
* @author Niklas Lindblad
*/
$data = $data['data']['items'][0];
$content['service'] = 'youtube';
$content['type'] = 'video';
$content['title'] = $data['title'];
$content['length'] = $data['duration'];
$content['video_id'] = $data['id'];
$content['description'] = $data['description'];
$content['thumbnail'] = $data['thumbnail']['hqDefault'];
return $content;
}
示例10: filter_http_request_args
/**
* Filter the arguments for HTTP requests. If the request is to a URL that's part of
* something we're handling then filter the arguments accordingly.
*
* @author John Blackbourn
* @param array $args HTTP request arguments.
* @param string $url HTTP request URL.
* @return array Updated array of arguments.
*/
public function filter_http_request_args(array $args, $url)
{
if (preg_match('#://api\\.wordpress\\.org/(?P<type>plugins|themes)/update-check/(?P<version>[0-9\\.]+)/#', $url, $matches)) {
switch ($matches['type']) {
case 'plugins':
return $this->plugin_request($args, floatval($matches['version']));
break;
case 'themes':
return $this->theme_request($args, floatval($matches['version']));
break;
}
}
$query = parse_url($url, PHP_URL_QUERY);
if (empty($query)) {
return $args;
}
parse_str($query, $query);
if (!isset($query['_euapi_type']) or !isset($query['_euapi_file'])) {
return $args;
}
if (!($handler = $this->get_handler($query['_euapi_type'], $query['_euapi_file']))) {
return $args;
}
$args = array_merge($args, $handler->config['http']);
return $args;
}
示例11: __construct
/**
* Constructor
*/
public function __construct()
{
$this->settings = get_option('woocommerce_amazon_payments_advanced_settings');
if (empty($this->settings['cart_button_display_mode'])) {
$this->settings['cart_button_display_mode'] = 'button';
}
if (empty($this->settings['seller_id'])) {
$this->settings['seller_id'] = '';
}
if (empty($this->settings['sandbox'])) {
$this->settings['sandbox'] = 'yes';
}
if (empty($this->settings['enabled'])) {
$this->settings['enabled'] = 'no';
}
if (empty($this->settings['hide_standard_checkout_button'])) {
$this->settings['hide_standard_checkout_button'] = 'no';
}
$this->reference_id = !empty($_REQUEST['amazon_reference_id']) ? $_REQUEST['amazon_reference_id'] : '';
if (isset($_POST['post_data'])) {
parse_str($_POST['post_data'], $post_data);
if (isset($post_data['amazon_reference_id'])) {
$this->reference_id = $post_data['amazon_reference_id'];
}
}
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_links'));
add_action('init', array($this, 'init_gateway'));
add_action('wp_loaded', array($this, 'init_handlers'), 11);
add_action('wp_footer', array($this, 'maybe_hide_standard_checkout_button'));
}
示例12: load
/**
* Loads the entire menu table into memory.
*
* @return boolean True on success, false on failure
*
* @since 1.5
*/
public function load()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select('m.id, m.menutype, m.title, m.alias, m.note, m.path AS route, m.link, m.type, m.level, m.language')->select($db->quoteName('m.browserNav') . ', m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id')->select('e.element as component')->from('#__menu AS m')->join('LEFT', '#__extensions AS e ON m.component_id = e.extension_id')->where('m.published = 1')->where('m.parent_id > 0')->where('m.client_id = 0')->order('m.lft');
// Set the query
$db->setQuery($query);
try {
$this->_items = $db->loadObjectList('id');
} catch (RuntimeException $e) {
JError::raiseWarning(500, JText::sprintf('JERROR_LOADING_MENUS', $e->getMessage()));
return false;
}
foreach ($this->_items as &$item) {
// Get parent information.
$parent_tree = array();
if (isset($this->_items[$item->parent_id])) {
$parent_tree = $this->_items[$item->parent_id]->tree;
}
// Create tree.
$parent_tree[] = $item->id;
$item->tree = $parent_tree;
// Create the query array.
$url = str_replace('index.php?', '', $item->link);
$url = str_replace('&', '&', $url);
parse_str($url, $item->query);
}
return true;
}
示例13: submit
public function submit($params, $radio)
{
//教务网登录
$this->login();
//获取评教参数
try {
$http = new Http(array(CURLOPT_URL => $this->baseUrl . 'jxpjgl.do?' . $params, CURLOPT_COOKIE => $this->cookies, CURLOPT_TIMEOUT => 3));
} catch (\Exception $e) {
throw new \Exception('网络异常,评教参数获取失败', Config::RETURN_ERROR);
}
$pattern = '/radioXh="0" value="(.*?)">(?:.*?)radioXh="1" value="(.*?)">(?:.*?)radioXh="2" value="(.*?)">(?:.*?)radioXh="3" value="(.*?)">/s';
preg_match_all($pattern, $http->content, $temp);
if (count($temp[0]) != 10) {
throw new \Exception('评教失败,请教参数有误', Config::RETURN_ERROR);
}
$mark = array($temp[1], $temp[2], $temp[3], $temp[4]);
//构造get与post参数
$get = 'method=savePj&tjfs=2&val=';
for ($i = 0; $i < 10; $i++) {
$get .= urlencode($mark[$radio[$i]][$i]) . ($i == 9 ? '' : '*');
}
parse_str($params, $temp);
try {
$http = new Http(array(CURLOPT_URL => $this->baseUrl . 'jxpjgl.do?' . $get, CURLOPT_POSTFIELDS => "type=2&pj09id=&pjdw=3&xsflid=&typejsxs=xs&pjfl=&pj01id={$temp['pj01id']}&pj05id={$temp['pj05id']}&jg0101id={$temp['jg0101id']}&jx0404id={$temp['jx0404id']}&pj0502id={$temp['pj0502id']}&jx02id={$temp['jx02id']}", CURLOPT_COOKIE => $this->cookies, CURLOPT_TIMEOUT => 3));
} catch (\Exception $e) {
throw new \Exception('网络异常,评教提交失败', Config::RETURN_ERROR);
}
if (false === stripos($http->content, '提交成功!')) {
throw new \Exception('未知错误,评教提交失败', Config::RETURN_ERROR);
}
return true;
}
示例14: getDateRange
public function getDateRange()
{
$filter = $this->getParam($this->getVarNameFilter(), null);
if (is_null($filter)) {
$filter = $this->_defaultFilter;
}
$data = array();
if (is_string($filter)) {
$filter = base64_decode($filter);
parse_str(urldecode($filter), $data);
$filter = $data;
}
if ($filter) {
if (isset($filter['report_from'])) {
$data['report_from'] = Mage::app()->getLocale()->date($filter['report_from'], Mage::app()->getLocale()->getDateFormat('short'), null, false);
}
if (isset($filter['report_to'])) {
$data['report_to'] = Mage::app()->getLocale()->date($filter['report_to'], Mage::app()->getLocale()->getDateFormat('short'), null, false);
}
} else {
$data = $this->_defaultFilters;
}
if (!isset($data['report_from'])) {
// getting all reports from 2001 year
$data['report_from'] = new Zend_Date(mktime(0, 0, 0, 1, 1, 2001));
}
if (!isset($data['report_to'])) {
$data['report_to'] = new Zend_Date();
$data['report_to']->addDay(1);
// tomorrow at 0am; otherwise today's donations will not be displayed
}
//var_dump("{$data['report_from']} {$data['report_to']}");
return $data;
}
示例15: parse
/**
* Parses an URI string returning an array of connection parameters.
*
* When using the "redis" and "rediss" schemes the URI is parsed according
* to the rules defined by the provisional registration documents approved
* by IANA. If the URI has a password in its "user-information" part or a
* database number in the "path" part these values override the values of
* "password" and "database" if they are present in the "query" part.
*
* @link http://www.iana.org/assignments/uri-schemes/prov/redis
* @link http://www.iana.org/assignments/uri-schemes/prov/redis
*
* @param string $uri URI string.
*
* @throws \InvalidArgumentException
*
* @return array
*/
public static function parse($uri)
{
if (stripos($uri, 'unix') === 0) {
// Hack to support URIs for UNIX sockets with minimal effort.
$uri = str_ireplace('unix:///', 'unix://localhost/', $uri);
}
if (!($parsed = parse_url($uri))) {
throw new \InvalidArgumentException("Invalid parameters URI: {$uri}");
}
if (isset($parsed['host']) && false !== strpos($parsed['host'], '[') && false !== strpos($parsed['host'], ']')) {
$parsed['host'] = substr($parsed['host'], 1, -1);
}
if (isset($parsed['query'])) {
parse_str($parsed['query'], $queryarray);
unset($parsed['query']);
$parsed = array_merge($parsed, $queryarray);
}
if (stripos($uri, 'redis') === 0) {
if (isset($parsed['pass'])) {
$parsed['password'] = $parsed['pass'];
unset($parsed['pass']);
}
if (isset($parsed['path']) && preg_match('/^\\/(\\d+)(\\/.*)?/', $parsed['path'], $path)) {
$parsed['database'] = $path[1];
if (isset($path[2])) {
$parsed['path'] = $path[2];
} else {
unset($parsed['path']);
}
}
}
return $parsed;
}