There may be no content, please take less bricks.
The first is the PHP version.
The
code is as follows:
<?php Echo mb_strimwidth ("Here is content", 0,3, "...", "utf-8");?>
In fact, you can use only a mb_strimwidth function, which is described as follows:
Mb_strimwidth-gets the string truncated by the specified width
String Mb_strimwidth (string $str, int $start, int $width [, String $trimmarker = "" [, String $encoding = Mb_internal_ Encoding ()]])
Parameter description:
$str to the string to truncate (that is, the original string, the output string)
$start intercept from the first few characters, the default is 0
$width the desired trim width
After $trimmarker interception, the content added at the end of the string (Common for ...). Indicates ellipsis), I am null by default
$encoding This parameter is important, if the string is Chinese, it must be added. Otherwise.... You can see the "" This thing has not been carefully read this function, in the WordPress theme because to display a small piece of content, and then the end of the garbled, and for a long time do not know why. In addition, this parameter should be consistent with the code format of the Web page, the personal test when the page code utf-8, parameters written as GBK when the Chinese characters on the shit. (Daniel explained)
PHP version of this, and sometimes think it is the problem of PHP language, in fact, we did not study it carefully.
JS version of:
SUBSTRING () and substr () method, two methods * almost * no difference,
The first parameter of the substring () method is required, the position of the first character in the string for the substring to be fetched, the second argument is optional, the last character of the substring to extract is 1 bits in the Stringobject, the default none, to the end of the string.
SUBSTR () The first parameter is required. The starting subscript of the substring to extract. Must be a numeric value. If it is a negative number, the argument declares the position from the tail of the string. In other words,-1 refers to the last character in the string, 2 to the penultimate character, and so on. The second parameter is optional. The number of characters in the substring. Must be a numeric value. If this argument is omitted, the string from the start position of the stringobject to the end is returned.
Example:
The
code is as follows:
<script type= "Text/javascript" >
var str= "Hello world!"
document.write (str.substring (3))
</script>
This example output: Lo world!
Starting with the third digit of the original string, to the end
The
code is as follows:
<script type= "Text/javascript" >
var str= "Hello world!"
document.write (str.substring (3,7))
</script>
This example output: Lo W
Starting at the fourth bit of the original string, to the seventh position
The
code is as follows:
<script type= "Text/javascript" >
var str= "Hello world!"
document.write (STR.SUBSTR (3))
</script>
Output: Lo world!
Third place begins to end
Copy Code code as follows:
<script type= "Text/javascript" >
var str= "Hello world!"
document.write (Str.substr (3,7))
</script>
Output: Lo worl
From fourth place, intercept 7 bits.
The third one is CSS.
CSS interception primarily uses the Text-overflow attribute.
Text-overflow: [Clip | ellipsis | <string>]
The default value is clip, that is, when the content is out of the container, the Text-overflow text is trimmed out, when the value is ellipsis, the ellipsis is substituted for the excess text, or a specific string is used to replace the excess text (currently only Firefox support).
An example of an ellipsis:
The
code is as follows:
. ellipsis{
Overflow:hidden;
White-space:nowrap;
text-overflow:ellipsis;
}