How to get the first 20 characters of the non-English string in PHP
How to get the first 20 characters of the non-English string in PHP
1 Answer
Using mb_strlen() function to get the string length
after that check, if the length greater than 20 or less
if string greater than 20 we use mb_substr() function to slice the first 20 characters
if string less than 20 print the string
Example
<?php
$str = "أبجد هوز حط كلمن سعفص قرشت";
echo (mb_strlen($str,'utf8')>20?mb_substr($str,0,20):$str);
?>ا
answer Link