A very important technique in PHP is to intercept characters of a specified length in a specified string. PHP pre-defined functions for string interception can be used
substr ()function to implement. The following is an introduction to the syntax of
First, explode$str = ' Data:image/png;base64,ivborw0kggoaaaansuheugaaalcaaaeccaiaaabc8mukaaag ... '; $TMPARR Explode $str ); $a $TMPARR [0]; $b $TMPARR [1];Where the OP number is 11 and 7 different functions are used to perform the operationSecond,
Used today in the project to remove the last character in the string
The original string 1,2,3,4,5,6,
Remove the last character "," and the end result is 1,2,3,4,5,6
The code is as follows:
Copy Code code as follows:
$str = "1,2,3,4,5
We all know that in JS string intercept characters have functions substr and substring, that PHP, PHP is not directly available substring functions, but there are substr functions.Do not believe that you can test. The following is the correct code.
In Oracle/PLSQL, The substr functions allows you to extract a substring from a string.
The syntax for the substr function is:
Substr (string, start_position, [length])Note:String is the source string.Start_position is the position for
PHP's substr function fully simulates ASP's right function. some people say that substr can completely replace ASP's right function right & nbsp; (x) substr ($ str,-x); & nbsp; however, if x0 is used, it cannot be replaced at all. Is there any way
Instr usage in Oracle:The format of the instr method isInstr (source string, the string to be searched, starting from the nth character, to find the nth matching serial number)Returns the location found. If not, 0 is returned.For example, in instr ('
About define (' Discuz_root ', substr (DirName (__file__), 0,-7)); Understanding define (' Discuz_root ', substr (DirName (__file__), 0,-7)) ;Get site root directoryFor the above statement has not understood what is meant to check the relevant
Several character truncation functions are provided for us in php, including substr, mb_substr, and mb_strcut functions. Some php Beginners use substr to intercept Chinese characters and find Chinese characters contain garbled characters, we can use
: This article mainly introduces the correct usage of substr and substring in PHP and the introduction of related parameters. if you are interested in the PHP Tutorial, refer to it. As we all know, the string truncation functions in js include
substr function string interception usage analysis in PHP, PHPSUBSTR
This example describes the use of SUBSTR function string interception in PHP. Share to everyone for your reference, as follows:
The SUBSTR function in PHP is defined as
Select GRP, site, item, sum (plan_qty), sum (diff_qty)
From (
Select/* case
When substr (productid, 1, 1) = 'l' then
'Sesl'
When substr (productid, 1, 1) = 'M' then
'Lcm'
Else
Substr (productid, 1, 1)
End "GRP ",*/
Decode (substr (productid, 1, 1),
Often see a novice asked PHP there is no similar to the ASP's left function or right function, to intercept a string on the left-hand side or the beginning of the N-character function. Of course the answer is yes. The SUBSTR function in PHP can do
1:update table Name set column name = SUBSTR (column name, INSTR (column name, ' match character ', "+1") Where condition like '%*% '2:select SUBSTR (column name, INSTR (column name, ', ', +1) as D from table name T where condition like '%-%
This article mainly introduces the differences and usage of substring and substr in js. Each step has a corresponding text description. If you are interested, refer to before you start.
Review the subscript in js (array element/character subscript
Summary of the differences between STRSTR, STRRCHR, substr, stristr four functions in PHP, STRSTRSTRISTR
PHP strstr, STRRCHR, substr, stristr four function usage differences:
PHP strstr STRRCHR substr stristr These four string manipulation
Substr () function Chinese normal substr () function can obtain the specified length of the string, but in case of Chinese, garbled characters may be generated at the end of the new string, the following function converts a string that exceeds the
The string function substr () in php (). Syntax of the string function substr () in php: stringsubstr (string $ stringint $ start [, int $ end]). This function is also intercepted in bytes (not characters, when intercepting Chinese characters, note
SUBSTR (str,start,length);
Example: substr (' PHP tutorial is very good language ', 4,5);
The output is the is ve;
When the length of the START>STR, it is returned as ();
substr (' PHP is very good language ', 26,5);
substr (' PHP is very good
In php, The strstr, strpos, substr, strrchr, and stripos functions are usually used to find out whether a character exists in a string. If you need to know about them, please refer to them.
1. strstr-first appearance of the search string
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.