Reputation: 8369
I am developing a church website in which I am showing the history of the church as brief in the home page. The code I have done is shown below:
function getabout($msg)
{
if (strlen($msg) > 750)
{
$message=substr($msg, 0, strpos($msg, ' ', 750));
}
else
{
$message=$msg;
}
$message=$message."...";
return $message;
}
This will work fine if the content is English. But when I tried with unicode language like malayalam, it is displaying characters less than 750.
How can I solve this problem. Thanks in advance.
Upvotes: 0
Views: 126
Reputation: 19915
The strlen function is not suited for multibyte strings. Use multibyte functions instead.
In your case use mb_strlen and mb_strpos.
http://php.net/manual/fr/function.mb-strlen.php
Upvotes: 1