How to replace the original Arabic letter form using PHP?

I have an Arabic text and you want to replace the "Initial" and "Medial" forms of some letters (not all forms) with other letters or symbols;

Example:

$text = '...وقد تم تصميم وبناء جميع مكونات الطائرة';

I need to replace the Initial form of the letter "ت", which is in the word "تم" with another letter; the available "ت" in "مكونات", which is the final form of this letter, is not replaced.

It seems that character codes (Unicode) cannot be used str_replace()to find a specific form of writing and replace it.

Note:

Most Arabic letters have different meanings:

  • Initial form: used at the beginning of a word, for example "ت" in "تم".
  • Medial form: used in the middle of a word, for example, "ت" in "نستعين".
  • Final form: used in the last word, for example "ت" in "مكونات".

see wikipedia.org for more information.

+4
source share
2 answers

Here I gave a piece of code ... the vampire will work $text = '...وقد تم تصميم وبناء جميع مكونات الطائرة'; $a=array('ت','تم'); $b=array('ت','مكونات');`` echo str_replace($a,$b,$text);

0
source

Letter shapes are used for output only. They cannot be stored and / or manipulated in this way. You must find another way to do what you want.

Try RegExp. This can help you. http://php.net/manual/en/regexp.reference.unicode.php

, str_replace, .

str_replace(
  ' ت',
  ' وت',
  $string
);
-1

All Articles