PHP Limit article content display word count

Source: Internet
Author: User
PHP Limit article content display word count

Http://www.3qphp.com/index/show/index/184.html

 
 $strleng) return$str;//string length is less than the specified number of words, the return string itself $notchinanum = 0;//initial is not the character count of the kanji for ($i =0; $i < $cutleng; $i + +) {if (Ord ( substr ($str, $i, 1)) <=128) {$notchinanum + +;}} if ($cutleng%2==1) && ($notchinanum%2==0))//If you want to intercept an odd number of characters, the characters in the length range to be truncated must contain an odd number of non-Chinese characters, otherwise the length of the interception plus a {$cutleng + +;} if ($cutleng%2==0) && ($notchinanum%2==1))//If you want to intercept an even number of characters, the length of the range of characters must contain an even number of non-Chinese characters, otherwise the length of the interception plus a {$cutleng + +;} Return substr ($str, 0, $cutleng);}? >

2. Call this function when needed---cutstr
For example:

Click to view the expanded full text

The above describes the PHP limit article content display words, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.