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;
PHP Source Analysis DZX1.5 string truncation function Cutstr usage
This article describes the PHP source code analysis of the DZX1.5 string truncation function cutstr usage. Share to everyone for your reference. The specific analysis is as follows:
?
123456789101112131415161718192021st2223242526272829303132333435363738394041424344454647484950
/** * Function source DZX1.5, file location/source/function/function_core.php */ Define (' CHARSET ', ' UTF-8 '); function Cutstr
substr instance
$content = ' I love you www.111cn.net ';
$temp = substr ($content, 4);
Echo $temp;
Results:
Love you www.111cn.net '//
Let's take a look at the function from the right.
$temp = substr ($temp, 0,-4);
The results are:
I love www.111c
OK, let's take a look at the Chinese intercept function.
function Moocutstr ($string, $length, $dot = ' ... ') {Global $charset;
if (strlen ($string) return $string;}$string = str_replace (Array (' amp; ', ' quot; ', ' $strcut = ';if (Strto
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.