Skip to content

Instantly share code, notes, and snippets.

@bobwol
Created August 18, 2021 23:56
Show Gist options
  • Save bobwol/3e750331c156e584ba526b4bf5ecad26 to your computer and use it in GitHub Desktop.
Save bobwol/3e750331c156e584ba526b4bf5ecad26 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