Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use substring on non english characters?

i have small site where i display search results of posts titles, some titles are up to 255 characters long and while displaying those in html table , the table's row breaks i.e. doesnt shows correct so i use substr php function to trim the title so that it can fit in table row.

For english titles it working great but for non-english titles it shows blank space i.e. trim everything.

i am using substr like this

<a href="<? echo $link; ?>" class="strong"><? echo htmlspecialchars(substr($row['title'],0,70)); ?></a>

so how can i make the non-english titles also of characters 70 ?


1 Answers

You should use multi-byte safe substr() operation based on number of characters for UTF-8:

mb_substr();

http://php.net/manual/en/function.mb-substr.php

like image 53
l'L'l Avatar answered Sep 05 '25 01:09

l'L'l



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!