~ Questions about displaying custom length strings

Source: Internet
Author: User
Help ~~ I have written a function for displaying custom string lengths. the code is as follows: PHPcodefunction_word_num ($ string, $ length) {$ stringtrim ($ string ); if (strlen ($ string) & gt; $ length) {return (mb help ~~ Question about displaying custom length strings
I wrote a function with a custom string length. the code is as follows:
PHP code
  Function _ word_num ($ string, $ length) {$ string = trim ($ string); if (strlen ($ string) >$ length) {return (mb_substr ($ string, 0, $ length, "gbk "). "... ") ;}else {return $ string ;}}


The problem is that after using this function, no matter whether the length is consistent or not, "..." is added to all of them for explanation ..

------ Solution --------------------
I also think the code is okay. maybe I think the character string uploaded by the landlord is Chinese, but the landlord needs to know that the strlen in Chinese is twice that in English, pay attention to the length.
If the owner knows it, then I don't know why.
------ Solution --------------------
The code is correct...
------ Solution --------------------
Provide your test data.

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.