Skip to content

Instantly share code, notes, and snippets.

@kcassam
Last active December 24, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcassam/6807151 to your computer and use it in GitHub Desktop.
Save kcassam/6807151 to your computer and use it in GitHub Desktop.
Fonction slug en php

Pour référence, voici la fonction slug que j'utilise en php quand j'en ai besoin

function slug($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|copy|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), '-'));
}

Inspiré de stackoverflow.com/questions/2103797

Ça marche mais pas idéal, si quelqu'un a mieux, je prends.
Comme précisé dans les commentaires sur la question dans stackoverflow, cette fonction pourrait être améliorée/généraliséee en utilisant la fonction iconv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment