<?php
function removeAcentos($string, $slug = false) {
// Código ASCII das vogais
$ascii['a'] = range(224, 230); $ascii['e'] = range(232, 235); $ascii['i'] = range(236, 239); $ascii['u'] = range(249, 252);
// Código ASCII dos outros caracteres
$ascii['b'] = array(223); $ascii['c'] = array(231); $ascii['d'] = array(208); $ascii['n'] = array(241); $ascii['y'] = array(253, 255);
foreach ($ascii as $key=>$item) {
$acentos = '';
foreach ($item AS $codigo) $acentos .= chr($codigo); $troca[$key] = '/['.$acentos.']/i';
}
// Slug?
if ($slug) {
// Troca tudo que não for letra ou número por um caractere ($slug)
// Tira os caracteres ($slug) repetidos
$string = preg_replace('/' . $slug . '{2,}/i', $slug, $string); $string = trim($string, $slug); }
return $string;
}
echo removeAcentos ('Ação, Comédia, Ficção Cientifica', '-');
PD9waHAKCiAgICAgICBmdW5jdGlvbiByZW1vdmVBY2VudG9zKCRzdHJpbmcsICRzbHVnID0gZmFsc2UpIHsKICAkc3RyaW5nID0gc3RydG9sb3dlcigkc3RyaW5nKTsKCiAgLy8gQ8OzZGlnbyBBU0NJSSBkYXMgdm9nYWlzCiAgJGFzY2lpWydhJ10gPSByYW5nZSgyMjQsIDIzMCk7CiAgJGFzY2lpWydlJ10gPSByYW5nZSgyMzIsIDIzNSk7CiAgJGFzY2lpWydpJ10gPSByYW5nZSgyMzYsIDIzOSk7CiAgJGFzY2lpWydvJ10gPSBhcnJheV9tZXJnZShyYW5nZSgyNDIsIDI0NiksIGFycmF5KDI0MCwgMjQ4KSk7CiAgJGFzY2lpWyd1J10gPSByYW5nZSgyNDksIDI1Mik7CgogIC8vIEPDs2RpZ28gQVNDSUkgZG9zIG91dHJvcyBjYXJhY3RlcmVzCiAgJGFzY2lpWydiJ10gPSBhcnJheSgyMjMpOwogICRhc2NpaVsnYyddID0gYXJyYXkoMjMxKTsKICAkYXNjaWlbJ2QnXSA9IGFycmF5KDIwOCk7CiAgJGFzY2lpWyduJ10gPSBhcnJheSgyNDEpOwogICRhc2NpaVsneSddID0gYXJ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