📜  php 去除所有无效字符的 url - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:03.505000             🧑  作者: Mango

代码示例1
//replaces all invalid characters in a url with "-"
function url($url) {
   $url = preg_replace('~[^\\pL0-9_]+~u', '-', $url);
   $url = trim($url, "-");
   $url = iconv("utf-8", "us-ascii//TRANSLIT", $url);
   $url = strtolower($url);
   $url = preg_replace('~[^-a-z0-9_]+~', '', $url);
   return $url;
}
//usage:
$invalidURL = "https://example.com/~+test;
$validURL = url($invalidURL);