str::urlify PHP Method

urlify() static public method

Convert a string to a safe version to be used in an URL
static public urlify ( string $text ) : string
$text string The unsafe string
return string The safe string
    static function urlify($text)
    {
        $text = trim($text);
        $text = str::lower($text);
        $text = str_replace('ä', 'ae', $text);
        $text = str_replace('ö', 'oe', $text);
        $text = str_replace('ü', 'ue', $text);
        $text = str_replace('ß', 'ss', $text);
        $text = preg_replace("![^a-z0-9]!i", "-", $text);
        $text = preg_replace("![-]{2,}!", "-", $text);
        $text = preg_replace("!-\$!", "", $text);
        return $text;
    }

Usage Example

Ejemplo n.º 1
0
 static function fetch($file)
 {
     if (!file_exists($file)) {
         return array();
     }
     $content = f::read($file);
     $content = str_replace("", '', $content);
     $sections = preg_split('![\\r\\n]+[-]{4,}!i', $content);
     $data = array();
     foreach ($sections as $s) {
         $parts = explode(':', $s);
         if (count($parts) == 1 && count($sections) == 1) {
             return $content;
         }
         $key = str::urlify($parts[0]);
         if (empty($key)) {
             continue;
         }
         $value = trim(implode(':', array_slice($parts, 1)));
         $data[$key] = $value;
     }
     return $data;
 }
All Usage Examples Of str::urlify