Skip to content

Instantly share code, notes, and snippets.

@JackNUMBER
Last active February 17, 2023 14:18
Show Gist options
  • Save JackNUMBER/00244bf8d5a233e6d435dd8eddbc2a6e to your computer and use it in GitHub Desktop.
Save JackNUMBER/00244bf8d5a233e6d435dd8eddbc2a6e to your computer and use it in GitHub Desktop.
sanitize.php
<?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