static private function removeAccentedLetters($input){
for ($i = 0; $i < strlen($input); $i++) {
$input[$i]=self::simplify($input[$i]);
}
return $input;
}
static private function simplify($in){
switch ($in) {
case 'Á':
return 'A';
case 'á':
return 'a';
default:
return $in;
}
}
This is the code. Doesn't work. Any thoughts? Oh yeah. It always enters the dafault exit for any input. perhaps it is somethig to do with how php handles chars X strings? I don't know.
Instead of switching the character itself, switch the character code. It's dangerous to embed ASCII Extended characters directly in a string, raw. Sometimes even the editor you are using to write the code may save the characters incorrectly, if you have the wrong encoding specified.
You should use str_replace instead:
$input = str_replace(array('Á', 'á'), array('A', 'a'), $input);
That does the exact same work as your switch statement.
Yeah. I changed the code slightly to this
switch ($in) {
case 'B':
return 'A';
case 'b':
return 'a';
default:
return $in;
}
for testing purposes and it worked. Thanks to all.