Truncates a string. the length of the string is different from that of the string.
20) {$ prna = mb_substr ($ prna, 0,40, 'utf-8 '). ".... "; echo $ prna;} else {echo $ prna;}?>
I often cannot upload files. I don't know if the computer is faulty.
Result:
MicroSD? Produo DUO ?? ....
PSP3000? (3 ?)....
IPhone3GS SIM card (black )....
Nokia CA-101D short MicroUSB ???....
PSP2000 background? (Black )....
PSP2000? SOURCE connection? ....
3.5? Stash? (Black )....
IPhone transparent background plug (3 ?)....
Reply to discussion (solution)
This is best solved with css (by container width)
Because the string length is not equal to the pixel width
Even if your local display is aligned, the font used by the client is uncontrollable, which means that the pixel width is still variable.
Change the default font in the browser and you will understand.
Your computing is faulty.
Generally, the text on the page is displayed in the default format. Therefore, the display width of a Chinese character is considered to be the width of two letters.
If the font adopts a non-equal width font, the situation will be much more complicated and will not be discussed here
1 byte for letters and symbols
For gbk encoding, a Chinese character is 2 bytes, which exactly meets the above situation
For UTF-8 encoding, one Chinese character is 3 bytes, that is, each Chinese character requires an additional 1 byte, and the number of Chinese characters x 2/3 is required during the calculation of bytes.
Mb_substr is intercepted by characters. both Chinese and Western are considered as one. Gourd occupancy factor