1
I updated my PHP and my following Script which I used to transform the text without accents, and the spaces in strokes (-) no longer works in PHP due to the ereg_replace is obsolete.
<?php
$variavel = "Céu Azul";
$variavel_limpa = strtolower( ereg_replace("[^a-zA-Z0-9-]", "-", strtr(utf8_decode(trim($variavel)), utf8_decode("áàãâéêíóôõúüñçÁÀÃÂÉÊÍÓÔÕÚÜÑÇ"),"aaaaeeiooouuncAAAAEEIOOOUUNC-")) );
echo $variavel_limpa; // ceu-azul
?>
What would be the solution for me to perform the transformation of this string (removing accents and placing dash between spaces) to work in PHP 7.
It worked great! Thank you!
– Fydellys
Because this is the answer that points the best way, which makes a "check" of the characters, whether ANSI (Ios-8859-1 or windows-1252) or utf-8, transcribes in ASCII if possible and what is not possible you eliminate with the metacharacters, making it something functional, different from the
utf8_encode
that always expects UTF-8 and that will not solve "any input". I’m not saying it’s 100% infallible, it might "eat" a few letters, but it’s a much more efficient internal resource than putting together a rangeàáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ
and use utf8_decode. + 1– Guilherme Nascimento