am trying to remove duplicates values from Arabic string input but
`$input = "اللہ";
$step1 = preg_split("/(?<!^)(?!$)/u", $input);
$step2 = implode(' ',step1);
$step3 = array_unique(step2 );
echo "step3";`
i need output like this
ا ل ھ
am trying to remove duplicates values from Arabic string input but
`$input = "اللہ";
$step1 = preg_split("/(?<!^)(?!$)/u", $input);
$step2 = implode(' ',step1);
$step3 = array_unique(step2 );
echo "step3";`
i need output like this
ا ل ھ
2
Answers
Can you try this?
Instead of running a regular expression, you could use the multibyte function
mb_str_split()
from themb_string
library. It is made to handle special charsets. Your PHP config might already enable it to replace usual PHP functions, but in this case you should check your INI file, or you can add someini_set()
calls at the beginning of your code. But the easiest is just to call themb_*
functions.Secondly, as @CBroe pointed out, you made a few mistakes in your code by passing a string to a function that wants an array as parameter.
This is what you can do:
Output:
You can run it here: https://onlinephp.io/c/fe990