Retrieving accents from a string with PHP

3

I'm using friendly urls and to generate the link, I'm using it this way:

$string = $jm->NomeCategoria; // retorna roupa de verão
$hifen = preg_replace('/[ -]+/' , '-' , $string); // incluo o hífen
$acentos = preg_replace( '/['^~\'"]/', null, iconv( 'UTF-8', 'ASCII//TRANSLIT', $hifen)); // retiro as acentuações

With these commands it returns: summer clothing . I just need to retrieve the string correct summer clothing on another page, as I need to do the check in the database. I was able to remove the hyphen and put the spaces, how can I "return" accentuations of a string ?

    
asked by anonymous 20.10.2017 / 18:06

1 answer

3
Essentially there is no way. I would have, but the solution is so complex it does not pay. It would have to have other mechanisms to solve this, to maintain the accents, to have a code, to have a table with and without accent, has several ways to solve.

Depending on what you need you can search the database insensitively, which is usually the most correct way, so it ignores the accents in the search. Not for all cases, but I find the solution more appropriate.

    
20.10.2017 / 18:13