Truncates a string. the length is different from the string. the length is different. & lt ;? PHP & nbsp; $ prna = $ row ['description']; & nbsp; if (strlen ($ prna) & gt; 20) {$ prna = mb_substr ($ prna, 0,40, 'utf-8 '). "... truncates a string with different lengths.
Truncates a string with different lengths.
if(strlen($prna)>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 producer Produo DUO producer ....
PSP3000 sort (3 parts )....
IPhone3GS SIM card (black )....
Nokia CA-101D short MicroUSB data transmission ....
PSP2000 uses the background middleware (black )....
PSP2000 power source connection ....
3.5 Serial plug hoist (black )....
IPhone transparent plug (3) ...... share to: 20) {$ prna = mb_subst... 'data-pics = ''>
------ 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.
------ Solution --------------------
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