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.