当前位置: 首页>>代码示例>>PHP>>正文


PHP UrlHelper::getParameterFromQueryString方法代码示例

本文整理汇总了PHP中UrlHelper::getParameterFromQueryString方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlHelper::getParameterFromQueryString方法的具体用法?PHP UrlHelper::getParameterFromQueryString怎么用?PHP UrlHelper::getParameterFromQueryString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UrlHelper的用法示例。


在下文中一共展示了UrlHelper::getParameterFromQueryString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: extractInformationFromUrl

 /**
  * Extracts a keyword from a raw not encoded URL.
  * Will only extract keyword if a known search engine has been detected.
  * Returns the keyword:
  * - in UTF8: automatically converted from other charsets when applicable
  * - strtolowered: "QUErY test!" will return "query test!"
  * - trimmed: extra spaces before and after are removed
  *
  * The function returns false when a keyword couldn't be found.
  *     eg. if the url is "http://www.google.com/partners.html" this will return false,
  *       as the google keyword parameter couldn't be found.
  *
  * @see unit tests in /tests/core/Common.test.php
  * @param string $referrerUrl URL referrer URL, eg. $_SERVER['HTTP_REFERER']
  * @return array|bool   false if a keyword couldn't be extracted,
  *                        or array(
  *                            'name' => 'Google',
  *                            'keywords' => 'my searched keywords')
  */
 public function extractInformationFromUrl($referrerUrl)
 {
     $referrerParsed = @parse_url($referrerUrl);
     $referrerHost = '';
     if (isset($referrerParsed['host'])) {
         $referrerHost = $referrerParsed['host'];
     }
     if (empty($referrerHost)) {
         return false;
     }
     // some search engines (eg. Bing Images) use the same domain
     // as an existing search engine (eg. Bing), we must also use the url path
     $referrerPath = '';
     if (isset($referrerParsed['path'])) {
         $referrerPath = $referrerParsed['path'];
     }
     $query = '';
     if (isset($referrerParsed['query'])) {
         $query = $referrerParsed['query'];
     }
     // Google Referrers URLs sometimes have the fragment which contains the keyword
     if (!empty($referrerParsed['fragment'])) {
         $query .= '&' . $referrerParsed['fragment'];
     }
     $referrerHost = $this->getEngineHostFromUrl($referrerHost, $referrerPath, $query);
     if (empty($referrerHost)) {
         return false;
     }
     $definitions = $this->getDefinitionByHost($referrerHost);
     $searchEngineName = $definitions['name'];
     $variableNames = $definitions['params'];
     $key = null;
     if ($searchEngineName === 'Google Images' || $searchEngineName === 'Google' && strpos($referrerUrl, '/imgres') !== false) {
         if (strpos($query, '&prev') !== false) {
             $query = urldecode(trim(UrlHelper::getParameterFromQueryString($query, 'prev')));
             $query = str_replace('&', '&', strstr($query, '?'));
         }
         $searchEngineName = 'Google Images';
     } elseif ($searchEngineName === 'Google' && (strpos($query, '&as_') !== false || strpos($query, 'as_') === 0)) {
         $keys = array();
         $key = UrlHelper::getParameterFromQueryString($query, 'as_q');
         if (!empty($key)) {
             array_push($keys, $key);
         }
         $key = UrlHelper::getParameterFromQueryString($query, 'as_oq');
         if (!empty($key)) {
             array_push($keys, str_replace('+', ' OR ', $key));
         }
         $key = UrlHelper::getParameterFromQueryString($query, 'as_epq');
         if (!empty($key)) {
             array_push($keys, "\"{$key}\"");
         }
         $key = UrlHelper::getParameterFromQueryString($query, 'as_eq');
         if (!empty($key)) {
             array_push($keys, "-{$key}");
         }
         $key = trim(urldecode(implode(' ', $keys)));
     }
     if ($searchEngineName === 'Google') {
         // top bar menu
         $tbm = UrlHelper::getParameterFromQueryString($query, 'tbm');
         switch ($tbm) {
             case 'isch':
                 $searchEngineName = 'Google Images';
                 break;
             case 'vid':
                 $searchEngineName = 'Google Video';
                 break;
             case 'shop':
                 $searchEngineName = 'Google Shopping';
                 break;
         }
     }
     if (empty($key)) {
         foreach ($variableNames as $variableName) {
             if ($variableName[0] == '/') {
                 // regular expression match
                 if (preg_match($variableName, $referrerUrl, $matches)) {
                     $key = trim(urldecode($matches[1]));
                     break;
                 }
//.........这里部分代码省略.........
开发者ID:oyoy8629,项目名称:yii-core,代码行数:101,代码来源:SearchEngine.php


注:本文中的UrlHelper::getParameterFromQueryString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。