Question:
Hello all i need help i create small code alphabets to numbers code working perfect on english to numbers but when am trying to put arabic urdu alphabet to numbers function not working please help my problem in arabic need helpTHIS CODE Working Perfect on english alphabet
$input = “JHON”;
$remap = [
“a” => ‘1’,
“A” => ‘1’,
“b” => ‘2’,
“B” => ‘2’,
“c” => ‘3’,
“C” => ‘3’,
“J” => ‘100’,
“H” => ’10’,
“O” => ’90’,
“N” => ‘200’,
];
$array = [];
for ($i = 0; $i < strlen($input); $i++) {
$c = $input[$i];
$array[] = $remap[$c];
}
$star = "(" . implode(',', $array) . ")";
echo $star;
[/code]
$input = “ب”;
$remap = [
“ا” => ‘200’,
“ب” => ‘300’,
“ج” => ’50’,
“د” => ‘100’,
];
$array = [];
for ($i = 0; $i < strlen($input); $i++) {
$c = $input[$i];
$array[] = $remap[$c];
}
$star = "(" . implode(',', $array) . ")";
echo $star;
[/code]
Answer:
String indexing with[]
is not multibyte-safe. You need to use the mb_XXX
functions when processing languages like Arabic. ‘200’,
“ب” => ‘300’,
“ج” => ’50’,
“د” => ‘100’,
];
$array = [];
for ($i = 0; $i < mb_strlen($input); $i++) {
$c = mb_substr($input, $i, 1);
$array[] = $remap[$c];
}
$star = "(" . implode(',', $array) . ")";
echo $star;
[/code]
If you have better answer, please add a comment about this, thank you!