The result of this code:
echo trim('سلام؟', '؟');
Is �لام
.
Why? I don't even know what's �
supposed to be. Where does that come from?
The result of this code:
echo trim('سلام؟', '؟');
Is �لام
.
Why? I don't even know what's �
supposed to be. Where does that come from?
I think this is because it is right-toleft- language, You can use rtrim()
phpFiddle - Hit "Run F9" to execute
echo rtrim('سلام؟', '؟');
You can use rtrim()
.
This will remove white space from end of the string.
echo rtrim('سلام؟', '؟');
And your problem solved..
Your string char is arabic, which is in the reverse order. So you have to use rtrim().
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:
سلام