Gdn_Format::url PHP Method

url() public static method

Creates URL codes containing only lowercase Roman letters, digits, and hyphens.
public static url ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be formatted.
return string
    public static function url($Mixed)
    {
        if (!is_string($Mixed)) {
            return self::to($Mixed, 'Url');
        }
        // Preliminary decoding
        $Mixed = strip_tags(html_entity_decode($Mixed, ENT_COMPAT, 'UTF-8'));
        $Mixed = strtr($Mixed, self::$_UrlTranslations);
        $Mixed = preg_replace('`[\']`', '', $Mixed);
        // Convert punctuation, symbols, and spaces to hyphens
        if (unicodeRegexSupport()) {
            $Mixed = preg_replace('`[\\pP\\pS\\s]`u', '-', $Mixed);
        } else {
            $Mixed = preg_replace('`[\\W_]`', '-', $Mixed);
        }
        // Lowercase, no trailing or repeat hyphens
        $Mixed = preg_replace('`-+`', '-', strtolower($Mixed));
        $Mixed = trim($Mixed, '-');
        return rawurlencode($Mixed);
    }

Usage Example

示例#1
0
 /**
  *
  *
  * @param $Name
  * @param string $Code
  * @param string $Url
  */
 public function addLabel($Name, $Code = '', $Url = '')
 {
     if ($Code == '') {
         $Code = Gdn_Format::url(ucwords(trim(Gdn_Format::plainText($Name))));
     }
     $this->_Labels[] = array('Name' => $Name, 'Code' => $Code, 'Url' => $Url);
 }
All Usage Examples Of Gdn_Format::url