URL Slugs
Original source: http://stackoverflow.com/questions/2955251/php-function-to-make-slug-url-string
@param  String
@return String
328077
public function urlSlug($text)
    {
        // replace non letter or digits by -
        $text = preg_replace('~[^\\pL\d]+~u', '-', $text);

        // trim
        $text = trim($text, '-');

        // transliterate
        $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

        // lowercase
        $text = strtolower($text);

        // remove unwanted characters
        $text = preg_replace('~[^-\w]+~', '', $text);

        if (empty($text)) {
            return 'n-a';
        }

        return $text;
    }
1162590
private function createUniqueNumericSlug($slug)
    {
        if ($this->isNumericSlug($slug)) {
            // Extract last number and increment it
            $number = substr($slug, -1, 1);
            $number++;

            // Replace with new number
            $string = substr($slug, 0, strlen($slug) - 1) . $number;

            return $string;
        } else {
            return $slug;
        }
    }
1135998
protected function _url($url = null) {
		if ($url !== null) {
			return '/' . trim($url, '/');
		} elseif ($uri = $this->env('REQUEST_URI')) {
			list($uri) = explode('?', $uri, 2);
			$base = '/^' . preg_quote($this->_base, '/') . '/';
			return '/' . trim(preg_replace($base, '', $uri), '/') ?: '/';
		}
		return '/';
	}
548823
public static function url($url){

		$url = static::_nullValue($url);
		if(!$url){

			return $url;
		}

		$query = parse_url($url, PHP_URL_QUERY);
		if(!$query){

			return $url;
		}

		parse_str($query, $query_parts);

		// First urldecode to be sure that we do not re-encode the query parts.
		$query_parts = array_map('static::_nested_urldecode', $query_parts);

		// http_build_query will take care of the urlencode.
		return strtok($url, '?') . '?' . http_build_query($query_parts);
	}
1082149
public static function segmentUrl($url = null)
    {
        if (!is_null($url) && !empty($url)) {
            $url = $url;
        } else {
            $url = self::requestInstance()->getRequestUrl();
        }

        return explode('/', trim($url, '/'));
    }
177486
protected function parseUrl($url) : string
    {
        // Ignore if its a valid url already, or an anchor link
        if (is_string($url) &&
            (filter_var($url, FILTER_VALIDATE_URL) !== false || Str::startsWith($url, '#'))) {
            return $url;
        }


        return $this->url->url($url);
    }
562073
public function sluggify($string)
    {
        $human_name = strtolower($string);
        $human_name = str_replace('á', 'a', $human_name);
        $human_name = str_replace('é', 'e', $human_name);
        $human_name = str_replace('í', 'i', $human_name);
        $human_name = str_replace('ó', 'o', $human_name);
        $human_name = str_replace('ú', 'u', $human_name);
        $human_name = str_replace('ñ', 'n', $human_name);
        return preg_replace(array(
                '/[^a-zA-Z0-9]+/',
                '/-+/',
                '/^-+/',
                '/-+$/',
            ), array('-', '-', '', ''), $human_name);
    }
842700
public function getSlug() : ?string 
    {
        if ( ! $this->hasSlug()) {
            $this->setSlug($this->getDefaultSlug());
        }
        return $this->slug;
    }
367785
private function get_plugin_slug( $url ) {
		if ( $this->app->utility->starts_with( $url, 'https://wordpress.org/plugins/' ) ) {
			return trim( str_replace( 'https://wordpress.org/plugins/', '', $url ), '/' );
		}

		return false;
	}
1223210
public function accessUrlAccessManagement($slug)
    {
        if (empty($slug) || 'wp-login.php' === $slug) {
            return;
        }

        // Change login URL
        add_filter('login_redirect', function () use ($slug) {
            return site_url().$slug;
        });

        // Customize Site URL
        add_filter('site_url', function ($url) use ($slug) {
            return str_replace('wp-login.php', $slug, $url);
        }, 10, 3);

        // Make the redirection works properly
        add_filter('wp_redirect', function ($url) use ($slug) {
            return str_replace('wp-login.php', $slug, $url);
        }, 10, 2);
    }
1099712
public function urlQuerystring($url)
    {
        $querystring = $this->querystring();
        if (isset($this->timestamp) && !Utils::contains($querystring, $this->timestamp)) {
            $querystring = empty($querystring) ? ('?' . $this->timestamp) : ($querystring . '&' . $this->timestamp);
        }

        return ltrim($url . $querystring . $this->urlHash(), '/');
    }
626812
protected function sluggify($string = '')
    {
        if (!empty($string)) {
            $regexs = ['/[^\w\s_.-]|\s+?/', '/-+?/'];
            $replacer = ['-', ' '];
            $string = Inflector::camelize((preg_replace($regexs, $replacer, strtolower($string))));
        }
        return $string;
    }
1348129
private function parseUrl($url)
    {
        $parsed = parse_url($url);

        if ((count($parsed) === 1)
            && isset($parsed['path'])
            && (0 === strpos($parsed['path'], '?') || false !== strpos($parsed['path'], '&'))
        ) {
            $parsed = array(
                'query' => $parsed['path']
            );

            return $parsed;
        }

        return $parsed;
    }
1312558
public function parseUrl($url) {
		$url = parse_url($url);
		$url['vars'] = array();
		if (!isset($url['fragment'])) {
			$url['fragment'] = null;
		}
		if (isset($url['query'])) {
			parse_str($url['query'], $url['vars']);
		}

		return $url;
	}
127481
public static function makeValidUrl($string)
    {
        $protocols = ['http://', 'https://', 'ftp://'];

        if ($string != '') {
            foreach ($protocols as $p) {
                if (substr($string, 0, strlen($p)) == $p) {
                    return $string;
                }
            }
        }

        if ($string != '' && $string != 'http://') {
            $string = 'http://' . $string;
        }

        return $string;
    }
528963
public function getUrl($url)
    {
        if (!$url || starts_with($url, ['#', '//', 'mailto:', 'tel:', 'http'])) {
            return $url;
        }

        // Get URL root
        $root = $this->app->getSetting('url');

        $url = trim($root, '/') . '/' . trim($url, '/');

        // Force trailing slash
        if ($this->app->getSetting('url_trailing_slash', false)
            && ! strrchr(basename($url), '.')
        ) {
            $url = "{$url}/";
        }

        return $url;
    }
679241
private function cleanUrl($url)
    {
        if (strlen($url) > 1 && strrpos($url, '/') === strlen($url) - 1) {
            $url = substr($url, 0, -1);
        }
        if (strrpos($url, '.php') === strlen($url) - 4) {
            $url = substr($url, 0, -4);
        }
        return $url;
    }