Two php string truncation functions. 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. Two php tutorials are provided to intercept strings and two php intercept string functions are provided. they can automatically recognize Chinese characters. if you intercept an article, this is a good one. if you like it, come and have a look.
Two php tutorials ar
($ str, 22, 12); echo'';Var_dump (utf8_substr ($ str, 22,-6); echo'';Var_dump (utf8_substr ($ str, 9, 12); echo'';Var_dump (utf8_substr ($ str, 19, 12); echo'';Var_dump (utf8_substr ($ str, 28,-6); echo'';
Result: (no garbled characters are intercepted. You are welcome to test and submit a bug)String (12) "fdj"String (26) "fdj (1 is mfe ... "String (13) "13f trial 65 2"String (12) "Data fd"String (20) "dj (1 is mfe ... "
Share frequently used ones
Next let's take a look at the Chinese t
Update Time: 20120102
/**
* [Webodmin] (C) 2010-2099 Blank Inc.
* This was not a freeware, use was 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;
while ($n
$t = Ord ($string [$n]);
Here is a support for Chinese characters and English mixed with the interception function, including the HTML tag in the processing, let's take a look at this interception function.
Chinese and English string interception functions (including HTML), the instance code is as follows:
function Get_word ($string, $length, $dot = '.. ', $charset = ' GBK ') {
if (strlen ($string)
return $string;
}
$string = Str_replace (', ', ' ', ' ' ', '
$strcut = ";
if (Strtolower ($charset) = = ' Utf-8 ') {
$n
I have also written a PHP article digest generation method (function) before, but it is not very easy to use and garbled. now I release another function, which was removed from an open-source system, if you want to use the strip_tags () command to generate a digest, add strip_tags () to the function, add it by yourself. The following are functions:
The code is as follows:
Function cutstr ($ string, $ length, $ charset, $ dot) {// character, truncation length, character set, and TerminatorIf (
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 into the function, I did not engage, add it myself. Here is the function:
Copy the Code code as follows:
function Cutstr ($string, $length, $charset, $dot) {//characters, intercept length, character set, end symbolif (strlen ($string) return $string;}$pre = Chr (1);$end = Chr (1);Protect Special strings$string = str_replace (Array (' ', ' ' ', ' $strcut = ";if
Cut the php code of the string function based on Chinese characters. Copy the code as follows: define (CHARSET, UTF-8 ); the default encoding is *** used to cut the string according to Chinese characters * @ param $ string-string * @ param $ length-length * @ param $ doc-shrink
The code is as follows:
Define (CHARSET, 'utf-8'); // default system encoding/*** Trim strings based on Chinese characters* @ Param $ string-string* @ Param $ length-length* @ Param $ doc-Thumbnail suffix* @ Return ret
Php: string function method based on Chinese characters. Define (CHARSET, UTF-8 ); the default encoding is *** used to cut the string according to Chinese characters * @ param $ string-string * @ param $ length-length * @ param $ doc-scaling suffix * @ return returns the character with define (CHARSET, 'utf-8'); // default system encoding
/**
* Trim strings based on Chinese characters
* @ Param $ string-string
* @ Param $ length-length
* @ Param $ doc-Thumbnail suffix
* @ Return returns the st
Here we will share with you a function that uses php to intercept strings. it is very practical and recommended to partners in need. It is often seen that some new users have asked PHP whether there is a left function or right function similar to asp, which can take N characters from the left or right of a string. Yes, of course. The substr function in PHP can be used, but PHP merges the two functions into one. here we will share with you a better function for intercepting strings.
The code is
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.