Skip to content

Instantly share code, notes, and snippets.

@slopesweb
Created May 6, 2022 19:15
Show Gist options
  • Save slopesweb/55581fd2a905a9cf24896726315f4088 to your computer and use it in GitHub Desktop.
Save slopesweb/55581fd2a905a9cf24896726315f4088 to your computer and use it in GitHub Desktop.
Tirar acentos, caracteres especiais e espaços de titulos e frases para torna-los slug
<?php
function tirarAcentos($string){
$string = preg_replace(array("/(á|à|ã|â|ä)/","/(Á|À|Ã|Â|Ä)/","/(é|è|ê|ë)/","/(É|È|Ê|Ë)/","/(í|ì|î|ï)/","/(Í|Ì|Î|Ï)/","/(ó|ò|õ|ô|ö)/","/(Ó|Ò|Õ|Ô|Ö)/","/(ú|ù|û|ü)/","/(Ú|Ù|Û|Ü)/","/(ñ)/","/(Ñ)/","/(ç)/","/(Ç)/"),explode(" ","a A e E i I o O u U n N c C"),$string);
$char = array(' & ', 'ª ', ' (', ') ', '(', ')', ' - ', ' / ', ' /', '/ ', '/', ' | ', ' |', '| ', ' | ', '|', '_', '.', ' ');
return strtolower(str_replace($char, '-', $string));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment