When creating a function that returns false
if there are repeated letters in a word and true
if there is not the following test passes the characters:
$this->assertTrue(isIsogram('Heizölrückstoßabdämpfung'));
But fails the following test:
$this->assertFalse(isIsogram('éléphant'));
The function that is called is as follows:
function isIsogram(string $text) {
$letters = array_filter(str_split(strtolower($text)), function($value) {
$v = preg_replace('/[^a-zA-Z]/i', '', $value);
return !empty($v);
});
$uniq = array_unique($letters);
$diff = array_diff_assoc($letters, $uniq);
return count($diff) > 0 ? false : true;
}
With German letters the test is applied and passes normally however the letters é
are removed when using preg_replace
, how can I apply this validation to characters that we use in our language?