If the text length exceeds a certain amount, then truncation shows "more" Click to see the rest of the content, not super not show

Source: Internet
Author: User
Tags truncated
Text length exceeds a certain amount, then truncation shows "more" Click to see the rest of the content, not super not show
Text length more than a certain amount, then truncated display "More" click to see the rest of the content, do not display JS PHP implementation can have done the master please help


------Solution--------------------
Chinese words, with mbstring will be better.
------Solution--------------------
It can be solved with PHP. Use a For loop to intercept a string, when the condition determines whether the character is 2 bytes (Chinese characters) or 1 bytes (Letters, numbers) can be
------Solution--------------------
function Getsre ($STR, $len) {
$STRLRN =strlen ($STR);
if ($strlrn < $len) {
return $str;
}else{
Rerurn substr ($str, 0, $len). " ...";
}

}//I remember, it looks like this.
------Solution--------------------
Non-Chinese words good control, such as this.

        function Limitwords ($string, $limit = 250) {
if (strlen ($string) < $limit) {return $string;}
$regex = "/(. { 1, $limit}) \b/";
Preg_match ($regex, $string, $matches);
return $matches [1]. ' More ';
}


Chinese words, with mbstring, and before it is better to mb_convert_encoding (), unified code.
------Solution--------------------
With the CSS and JS control it can be
First CSS set a fixed height, beyond the hidden, add a more below, click on the time to set this height to auto can be
------Solution--------------------
CSS can manipulate CSS properties ah, when clicked more when the height of the CSS set to auto is displayed
------Solution--------------------
I'll write you a demo, it's simple.




Untitled Document


Test content testing Content test content test contents testing content test content test content test Content tests content test content test content test content test content test content test content test content test content test content test content test content test content test content test content test contents test Content Test content testing Content test content testing content test content test content test content test contents testing content test content test content test content test content test content test content test content test content test content test content test content test content test content test content test Content testing Contents testing content test Contents Content test content test Content testing content test contents test content test content test contents testing content test content test content test Content testing contents test content test content test content test content test content test content test content test content test content test content test content test content test contents Tolerance test content test content test contents test content test content test content test contents testing content test content test content test content test content test content test content test content test content test content test content test content test content test content test content test content test content test contents Test content test content test contents test Content content test content test content test contents test Content testing content test content test content test content test content test Contents testing Content test contents testing content test Content show more


------Solution--------------------
Do not use the background PHP to intercept, in that case also to consider Utf-8, trouble.
Direct full data to the previous paragraph, the previous paragraph through the CSS settings, can be truncated and "more" display.
  • 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.