I am trying to convert all of my UTF-8 characters to plain ASCII characters. I am looping trough every char of a string and based on the character I decide if character has to be changed. For ASCII chars it works fine but the code doesn't change UTF-8 characters.
here is my function:
function toNoUTFChars($inputString){
$stringArray = str_split($inputString);
$finalString = '';
foreach ($stringArray as $char) {
if($char == 'ě' || $char == 'é'){$finalString .= 'e';
}else if($char == 'š'){$finalString .= 's';
}else if($char == 'č'){$finalString .= 'c';
}else if($char == 'ř'){$finalString .= 'r';
}else if($char == 'ý'){$finalString .= 'y';
}else if($char == 'á'){$finalString .= 'a';
}else if($char == 'í'){$finalString .= 'i';
}else if($char == ' '){$finalString .= '-';
}else if($char == 'ú' || $char == 'ů'){$finalString .= 'e';
}else if($char == 'ň'){$finalString .= 'n';
}else if($char == 'ť'){$finalString .= 't';
}else if($char == 'ď'){$finalString .= 'd';
}else if($char == 'ó'){$finalString .= 'o';
}else if($char == 'ň'){$finalString .= 'n';
}else if(ctype_alpha($char)){
$finalString .= $char;
}
}
return $finalString;
}
Example input "Test Outputěěěččč with utf8ččč"
Expected output: "Test-Outputeeeccc-with-utf8ccc"
Output i am getting: "Test-Output-with-utf8" //Utf8 chars missing :(