Piwik\UrlHelper::isLookLikeUrl PHP Method

isLookLikeUrl() public static method

We don't need a precise test here because the value comes from the website tracked source code and the URLs may look very strange.
public static isLookLikeUrl ( string $url ) : boolean
$url string
return boolean
    public static function isLookLikeUrl($url)
    {
        return preg_match('~^(([[:alpha:]][[:alnum:]+.-]*)?:)?//(.*)$~D', $url, $matches) !== 0 && strlen($matches[3]) > 0;
    }

Usage Example

Example #1
0
 /**
  * Returns an array containing the following information:
  * - referer_type
  *        - direct            -- absence of referrer URL OR referrer URL has the same host
  *        - site                -- based on the referrer URL
  *        - search_engine        -- based on the referrer URL
  *        - campaign            -- based on campaign URL parameter
  *
  * - referer_name
  *         - ()
  *         - piwik.net            -- site host name
  *         - google.fr            -- search engine host name
  *         - adwords-search    -- campaign name
  *
  * - referer_keyword
  *         - ()
  *         - ()
  *         - my keyword
  *         - my paid keyword
  *         - ()
  *         - ()
  *
  * - referer_url : the same for all the referrer types
  *
  * @param string $referrerUrl must be URL Encoded
  * @param string $currentUrl
  * @param int $idSite
  * @return array
  */
 public function getReferrerInformation($referrerUrl, $currentUrl, $idSite)
 {
     $this->idsite = $idSite;
     // default values for the referer_* fields
     $referrerUrl = Common::unsanitizeInputValue($referrerUrl);
     if (!empty($referrerUrl) && !UrlHelper::isLookLikeUrl($referrerUrl)) {
         $referrerUrl = '';
     }
     $currentUrl = PageUrl::cleanupUrl($currentUrl);
     $this->referrerUrl = $referrerUrl;
     $this->referrerUrlParse = @parse_url($this->referrerUrl);
     $this->currentUrlParse = @parse_url($currentUrl);
     $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY;
     $this->nameReferrerAnalyzed = '';
     $this->keywordReferrerAnalyzed = '';
     $this->referrerHost = '';
     if (isset($this->referrerUrlParse['host'])) {
         $this->referrerHost = $this->referrerUrlParse['host'];
     }
     $referrerDetected = $this->detectReferrerCampaign();
     if (!$referrerDetected) {
         if ($this->detectReferrerDirectEntry() || $this->detectReferrerSearchEngine()) {
             $referrerDetected = true;
         }
     }
     if (!empty($this->referrerHost) && !$referrerDetected) {
         $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_WEBSITE;
         $this->nameReferrerAnalyzed = Common::mb_strtolower($this->referrerHost);
     }
     $referrerInformation = array('referer_type' => $this->typeReferrerAnalyzed, 'referer_name' => $this->nameReferrerAnalyzed, 'referer_keyword' => $this->keywordReferrerAnalyzed, 'referer_url' => $this->referrerUrl);
     return $referrerInformation;
 }
All Usage Examples Of Piwik\UrlHelper::isLookLikeUrl