PHP intercepts data with a value of more than 10 characters in the format of.. if not, what should I do?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.