PHP intercepts data with a value of more than 10 characters .... if there are insufficient fields in my database, there are six of them with a length of more than 100. if it is displayed on the page, the layout is not good, so I want to extract the six fields for ten characters .... is it a good idea for everyone? how can I query all the data in the database? how can I use PHP to intercept data with more than 10 characters .... not changed
In my database, there are six fields with a length of more than 100. if it is displayed on the page, the layout is poor, so I want to extract the six fields for ten characters .... indicates
Do you want to use some good ideas? Besides, when I query a database, all the queried data is stored in the collection.
How to write can be simpler
------ Solution --------------------
You can use the string truncation method to intercept the display ···
------ Solution --------------------
For fear of Chinese problems, use mbstring.
------ Solution --------------------
Discussion
You can use the string truncation method to intercept the display ···
------ Solution --------------------
PHP code
/*** ThumbHandler * @ access public * // * usage: Auto crop: The program will crop the largest square from the center according to the image size, scale down by target size $ t-> setSrcImg ("img/test.jpg"); $ t-> setCutType (1 ); // This sentence is OK $ t-> setDstImg ("tmp/new_test.jpg"); $ t-> createImg (60, 60); manual cropping: the program retrieves $ t-> setSrcImg ("img/test.jpg") from the source graph according to the specified position; $ t-> setCutType (2
------ Solution --------------------
Search online, a lot
The key is to consider the mixed Chinese and English characters. a Chinese character is two bytes.
------ Solution --------------------
In Chinese:
Function getSubStr ($ s)
{
$ Substr = strlen ($ s)> 20? Substr (0, 20, $ str). chr (0). '...': $ s;
Return $ substr; // 20 indicates 10 Chinese characters
}
If both Chinese and English are mixed, the ASCII code value is used to determine the number of English letters and the number of Chinese characters.