1

The result of this code:

echo trim('سلام؟', '؟');

Is �لام.

Why? I don't even know what's supposed to be. Where does that come from?

Martin AJ
  • 6,261
  • 8
  • 53
  • 111
  • 2
    Possible duplicate of [Multibyte trim in PHP?](https://stackoverflow.com/questions/10066647/multibyte-trim-in-php) – Nadav May 23 '17 at 09:12
  • [cut arabic string](https://stackoverflow.com/q/32680409/6521116) – LF00 May 23 '17 at 09:23

4 Answers4

1

I think this is because it is right-toleft- language, You can use rtrim()

phpFiddle - Hit "Run F9" to execute

echo rtrim('سلام؟', '؟');
Mi-Creativity
  • 9,554
  • 10
  • 38
  • 47
0

You can use rtrim().

This will remove white space from end of the string.

echo rtrim('سلام؟', '؟');

And your problem solved..

Virb
  • 1,639
  • 1
  • 16
  • 25
0

Your string char is arabic, which is in the reverse order. So you have to use rtrim().

LF00
  • 27,015
  • 29
  • 156
  • 295
0

rtrim is to replace from the right side of the string and it is OK for OP's requirement. But I think str_replace() is more appropriate. Trim can be done by it, also helpful to replace from any position of string. An example:

$search = ['؟', ' ',]; // Add more elements if required
$str = 'سلام؟';
$output = str_replace($search, '', $str);

echo $output;

Output:

سلام
Janie
  • 638
  • 9
  • 26