Answers for "php strip url of all invalid characters"

PHP
0

php strip url of all invalid characters

//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);
Posted by: Guest on August-02-2021

Code answers related to "php strip url of all invalid characters"

Browse Popular Code Answers by Language