• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: Alphabets to number converter but non english letter problem

Resolved: Alphabets to number converter but non english letter problem

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

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 help
THIS 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]

now problem is here when am put arabic alphabet in array not working

$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]

the answer is 300 but output is grabage etc please tell me how i can manage it

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!

php
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to scroll bottom of div at launch?

02/04/2023

Resolved: how to get and read an xml file in a zip file using xml.etree

02/04/2023

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.