Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP substr Persian string end with question mark

Tags:

php

In PHP when I want to substr the Persian string 'حروف فارسی برای امتحان', and it appends the question mark at the end of string.

This is my code:

$a = 'حروف فارسی برای امتحان'; echo substr($a,0,10);

And the problem is حروف �

Anyone has any suggestion or solution for this regards? much appreciated.

like image 220
Gulmuhammad Akbari Avatar asked Jul 23 '26 18:07

Gulmuhammad Akbari


1 Answers

use mb_substr($a,0,10,'utf-8') instead of substr() for Persian and Arabic characters

like image 132
Ali Abassi Avatar answered Jul 26 '26 12:07

Ali Abassi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!