So on my webpage I have an input form (with 'accept-charset="UTF-8"') for the user to enter text, which will get posted to a php page. In the php page, the input should be separated by spaces, then stored in an array, with a key value which equals the total count of letters in that word. There is no worry about words with the same length.
Example:
User inputs "def ghijk a bc"
$stringArr[1][0] = "a"
$stringArr[2][0] = "bc"
$stringArr[3][0] = "def"
$stringArr[5][0] = "ghijk"
I have this working all fine when it comes to English letters, but if I try to input letters from other languages, the key value is always wrong. Take this letter from Hindi for example: "मैं", it gives it a key value of 21 instead of just 1. What is the workaround to this?
$string = "मैं मैंमैं";
$stringLenArr = preg_split('/\s+/', $string);
$stringArr = array();
foreach($stringLenArr as $value) {
// What I used before:
// $stringArr[strlen($value)][] = $value;
// Attempted solution which still only works with English
$stringArr[mb_strlen($value, "UTF-8")][] = $value;
}
Just to make things clearer: There should only ever be a single language entered, so if the solution requires a language selection box on the input page, that is no issue.