Your range in [...]
is a-z
and 0-9
, a
to z
only consider the letters of the "alphabet" and not its variations, ally work with accents in slug URLs from my point of view is a bad idea, it would be more interesting to associate the slug with an id and url to be merely illustrative and without accents, which can be solved with functions like iconv
of PHP, but that is my opinion.
Modern browsers today believe that they work with UTF-8 in their urls, so maybe using the \u00C0-\u00FF
range will work (as in renan's answer: link ):
$slug = preg_replace('/[^a-z0-9\u00C0-\u00FF]+/ui', '-', trim(strtolower($_POST["titulo"])));
Some old browsers do not work with Unicode, so maybe the best thing to do is to use the first suggestion without accents, but that's a story beyond, maybe in another question I'll detail how to do something like this
You can even use the @bfavaretto response: link must have in mind that the accents may not work, because if the .php
document is saved with ANSI or iso-8859-1 / windows-1252 then it will fail with certainty, do you still want to use it as in the response of the @bfavaretto I recommend that you first read this answer calmly:
After reading and understanding how to use utf-8 properly you can try this:
$slug = preg_replace('/[^a-z0-9áàâãéèêíïóôõöúçñ]+/i', '-', trim(strtolower($_POST["titulo"])));