I have two strings
String 1: "sebastien"
String 2: "Sébastien"
I want to compare these two strings by ignoring é (Accents) character. Can anyone know this logic?
Thanks in advance
I have two strings
String 1: "sebastien"
String 2: "Sébastien"
I want to compare these two strings by ignoring é (Accents) character. Can anyone know this logic?
Thanks in advance
Calculate the similarity between two strings with similar_text function.
Before parse "é" with :
See more at: http://bitprison.net/php_normalize_string_function#sthash.tMoMbaOG.dpuf
Use Normalizer PHP extension or iconv, more info:
http://www.php.net/manual/en/class.normalizer.php http://www.php.net/manual/en/function.iconv.php <?php $string = 'Sébastien'; echo Normalizer::normalize($string); echo iconv('UTF-8', 'ASCII//TRANSLIT', $string); ?>
You can also use behat/transliterator package:
require_once 'vendor/autoload.php'; $stringWithoutAccent = 'acces'; $stringWithAccent = 'accès'; // true var_dump($stringWithoutAccent === \Behat\Transliterator\Transliterator::unaccent($stringWithAccent));
You can simply decode the strings in utf8 and compare them.
Otherwise, if by ignore, you meant not compare the character at all, then you might have to do a char-by-char comparison. First, get both strings to upper or lower case, and wherever you come across a non unicode character, skip the comparison and move to comparing the next char.