In the use of the time, you have to generate a summary of the content strip_tags (), of course, you can also add strip_tags () directly to the function, I did not engage, add it myself. Here's the function:
Copy Code code as follows:
function Cutstr ($string, $length, $charset, $dot) {//character, interception length, character set, end character
if (strlen ($string) return $string;
}
$pre = Chr (1);
$end = Chr (1);
Protect Special strings
$string = str_replace (Array (' ', '
length of the string is smaller than the length to be intercepted, the system returns// Strlen is used to obtain the length of a string. for example, if the string "happy new year" needs to be intercepted with four Chinese characters,// You must know the number of bytes of these four Chinese characters. Otherwise, the returned string may be "happy new year ..."If (strlen ($ string) Return $ string;}// Convert htmlspecialchars from the original string$ Pre = chr (1 );$ End = chr (1 );$ String =
number of bytes of these four Chinese characters. Otherwise, the returned string may be "Happy New Year ..."If (strlen ($ string) Return $ string;}// Convert htmlspecialchars from the original string$ Pre = chr (1 );$ End = chr (1 );$ String = str_replace (array ('', '"', '$ Strcut = ''; // initialize the return value// If it is UTF-8 encoded (this judgment is incomplete, it may be utf8)If (strtolower (CHARSET) = 'utf-8 '){// The initial continuous loop pointer $ n, the last digit $ tn, the num
characters, otherwise the returned string might be "Happy New Year ..."
if (strlen ($string) return $string;
}
Convert Htmlspecialchars in original string
$pre = Chr (1);
$end = Chr (1);
$string = str_replace (Array (' ', ' "'", ' $strcut = '; Initialize return value
If it's utf-8 code (this is a little incomplete, it could be UTF8)
if (Strtolower (CHARSET) = = ' Utf-8 ') {
The initial continuous loop pointer $n, the last number of digits $tn, the number of characters intercepted $
characters, otherwise the returned string may be "Happy New Year ..."
if (strlen ($string) return $string;
}
Convert the original string to Htmlspecialchars
$pre = Chr (1);
$end = Chr (1);
$string = str_replace (Array (' ', ' ' ', ' $strcut = "; Initialize return value
If it's utf-8 code (this is a bit incomplete, it could be UTF8)
if (Strtolower (CHARSET) = = ' Utf-8 ') {
The initial continuous loop pointer $n, the last word bit number $tn, the number of characters intercepted $
Php does not support Chinese very well. It is a problem to intercept Chinese and English characters in a string, and garbled characters may occur if the string is not properly processed, next we can take the Chinese character string function and handle it well. Php does not support Chinese very well. It is a problem to intercept Chinese and English characters in a string, and garbled characters may occur if the string is not properly processed, next we can take the Chinese character string funct
Use php to intercept a specified length. PHP language: the code used to copy string based on Chinese characters is as follows: functioncutstr ($ string, $ length, $ dot ...) {if (strlen ($ string) $ length) {return $ string ;}$ prechr (1); PHP language: trim strings based on Chinese characters
The code is as follows:
Function cutstr ($ string, $ length, $ dot = '...'){If (strlen ($ string) Return $ string;}$ Pre = chr (1 );$ End = chr (1 );$ String = str_replace (array ('', '"', '$ Strcut = ''
When using the strip_tags () command, you must add strip_tags () to the function. The following are functions:
Copy codeThe Code is as follows: function cutstr ($ string, $ length, $ charset, $ dot) {// character, truncation length, Character Set, and Terminator
If (strlen ($ string) Return $ string;
}
$ Pre = chr (1 );
$ End = chr (1 );
// Protect Special strings
$ String = str_replace (array ('', '"', '$ Strcut = '';
If (strtolower ($ charset) = 'utf-8 '){
$ N = $ tn = $
Php source code analysis using the DZX1.5 string truncation function cutstr
This article describes how to use the DZX1.5 string truncation function cutstr in php source code analysis. Share it with you for your reference. The specific analysis is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/** * Function source DZX1.5, file/source/function/function_core.php */ Defin
The following describes how to use php to intercept a specified length. For more information about how to use PHP to intercept a string, see the php language.
The code is as follows:
Function cutstr ($ string, $ length, $ dot = '...'){If (strlen ($ string) Return $ string;}$ Pre = chr (1 );$ End = chr (1 );$ String = str_replace (array ('', '"', '$ Strcut = '';If (strtolower (CHARSET) = 'utf-8 '){$ N = $ tn = $ noc = 0;While ($ n $ T = ord ($ string
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.