Last active
February 17, 2023 14:18
-
-
Save JackNUMBER/00244bf8d5a233e6d435dd8eddbc2a6e to your computer and use it in GitHub Desktop.
sanitize.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sanitize($string) { | |
return strtolower( | |
trim( | |
preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), | |
'-') | |
); | |
} | |
var_dump(sanitize(" Hey oH, c'est l'été ! ")); // "hey-oh-c-est-l-ete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment