English:
| The code is as follows |
|
function Tourl ($STR) { $str = preg_replace ('/[^a-za-z0-9]+/', '-', $str); $str = Trim ($str, '-'); Return Strtolower ($STR); } |
Contains special characters:
| code as follows |
|
| function Strtourl ($str) { $str = htmlentities ($str, Ent_quotes," UTF-8 "); $str = Preg_replace (' /& ([a-z]{1,2}) (?: Acute|lig|grave|ring|tilde|uml|cedil|caron);/I ', ' 1 ', $str); $str = Html_entity_decode ($str, Ent_quotes, "UTF-8"); $str = preg_replace ('/[^a-z0-9]+/i ', '-', $str); return Strtolower ($STR); } |
In addition to the above method PHP provides UrlEncode (), UrlDecode (), Rawurlencode (), Rawurldecode () function, use it can directly convert this is not introduced.
http://www.bkjia.com/PHPjc/737699.html www.bkjia.com true http://www.bkjia.com/PHPjc/737699.html techarticle English: Code is as follows function Tourl ($STR) {$str = preg_replace ('/[^a-za-z0-9]+/', '-', $str); $str = Trim ($str, '-'); return STRT Olower ($STR); } contains special characters: The code is as follows ...