Wednesday 6 November 2019

php - How can I make substr work with utf-8?

Why is my text not displayed properly when I use "substr"?


function limitstring($input,$number) {
if (strlen($input) > $number){
$input = substr($input, 0, $number) . '...';
}
return $input;
}

Input:


echo $row['text'];

Output: Käse


Input:


limitstring($row['text'],60);

Output:
K�se...

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...