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
Today, I encountered a problem of intercepting Chinese and English strings. in gbk, each word occupies two bytes in Chinese. if it is all Chinese, use the substr () function, however, if both Chinese and English are available, it will be troublesome. I found a good function in the previous code, which is a good implementation.
The code is as follows:
Function get_word ($ string, $ length, $ dot = '..', $ charset = 'gbk '){
If (strlen ($ string) Return $ string;
}
$ String = str_replace (array (
Here we provide an intercept function that supports mixing Chinese characters with English characters, including html tags. Let's take a look at this function. Here we provide an intercept function that supports mixing Chinese characters with English characters, including html tags. Let's take a look at this function.
Script ec (2); script
Chinese and English string truncation functions (including html)
Function get_word ($ string, $ length, $ dot = '..', $ charset = 'gbk '){If (strlen ($
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 TerminatorIf (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 = $
The following describes how to use php to intercept a specified length.
The following describes how to use php to intercept a specified length.
PHP language: Cut 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 = '';If (strtolower (CHARSET) = 'utf-8 '){$ N = $ tn = $ no
Today, I encountered a problem of intercepting Chinese and English strings. in gbk, each word occupies two bytes in Chinese. if it is all Chinese, use the substr () function, however, if both Chinese and English are available, it will be troublesome. I found a good function in the previous code, which is a good implementation.
Copy codeThe code is as follows:
Function get_word ($ string, $ length, $ dot = '..', $ charset = 'gbk '){
If (strlen ($ string) Return $ string;
}
$ String = str_replace
PHPsubistr truncated string without code
Time UPDATED: 20120102
/**
* [WebodMin] (C) 2010-2099 Blank Inc.
* This is NOT a freeware, use is subject to license terms
*
**/
Function subistr ($ string, $ length, $ dot = '...'){
Global $ charset;
If (strlen ($ string)
Return $ string;
}
$ S = '';
If (strtolower ($ charset) = 'utf-8 '){
$ N = $ tn = $ noc = 0
The Chinese and English string truncation function (including html) in php is provided here to support the intercept of Chinese characters and English characters, including html tags, let's take a look at this screenshot function.
The sample code is as follows:
Function get_word ($ string, $ length, $ dot = '..', $ charset = 'gbk '){
If (strlen ($ string)
Return $ string;
}
$ String = str_replace (array ('','', '', '"', '
$ Strcut = '';
If (strtolower ($ charset) = 'utf-8 '){
$ N = $ tn = $
This is the use of a phpwind inside a string interception function, he supports gbk,gbk2312,utf-8 and other encoded character interception, but also very efficient to support the processing of Chinese strings.
The code is as follows
Copy Code
function Substrs ($content, $length, $add = ' Y ') {if (strlen ($content) > $length) {if ($GLOBALS [' Db_charset ']!= ' Utf-8 ') {$retstr = ";for ($i =0; $i $retstr. = Ord ($content [$i]) > 127? $content [$i]. $content [+ + $i]: $c
date
* @param type $datecome the previous date
* @param the date after type $datego
* @return Type
*/
function Sub_date ($datecome, $datego) {
$d 1 = strtotime ($datecome);
$d 2 = strtotime ($datego);
$days = Round (($d 2-$d 1)/3600/24);
$days = $days
return $days;
}
/**
* Replace the contents of the $length behind $string with $dot
* @param string $string
* @param int $length
* @param string $dot
* @ret
PHP intercepts string functions to share, PHP intercepts strings
Often see a novice ask PHP there is no similar to the ASP of the left function or the right function, the implementation of a string to intercept a character or the beginning of the n characters of a function. The answer is of course there is. PHP substr function can be done, except that PHP has two functions in one, and here to share a more excellent function of intercepting the string.
Copy CodeThe code is as follows:/*** Method
Two php string truncation functions are provided. they can automatically recognize Chinese characters. if you are intercepting an article, this is a good one. if you like it, come and check it out. Article 1: lt ;? Phpheader ( quot; content-ty
Two php string truncation functions are provided. they can automatically recognize Chinese characters. if you are intercepting an article, this is a good one. if you like it, come and check it out.
Article 1:
Header ("content-type: text/html;
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.