~ questions about displaying custom length strings

Source: Internet
Author: User
Asking questions about displaying custom length strings
I wrote a custom string length function, 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 ... After using this function, regardless of the length of the match, all added "...", to explain:

------Solution--------------------
Code I also think no problem, maybe I think is the string is Chinese, but the landlord needs to know the Chinese strlen is twice times the English, then determine the length of time need to pay attention to.
If the landlord would have known, then I do not know why
------Solution--------------------
The code is really fine ...
------Solution--------------------
Give 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.