Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #strip #url #invalid #characters
ADD COMMENT
Topic
Name
7+7 =