This article mainly introduces PHP substr () and explode () function usage analysis, in the form of an instance of the substr () and explode () function to deal with the string of skills, is the use of high frequency function in string operation, has a certain practical value, A friend you need can refer to the following
This example describes the use of substr () and explode () functions in PHP. Share to everyone for your reference. Here's how:
SUBSTR (string,start,length): This function takes the string string of the beginning of the strings to remove the length of a character, if start is negative, then from the end of the string, if the parameters can be omitted length exists, but is negative, To the last length of the string, the instance code is as follows:
The code is as follows:
<?php echo substr ("abcdef", 1, 3); Returns "BCD" Echo substr ("ABCdef",-2); Returns "EF" Echo substr ("ABCdef",-3, 1); Returns "D" Echo substr ("abcdef", 1,-1); Return to "BCDE"?>
Explode (separator,string,limit): This function splits a string into an array separator specify where to split the string to be split, the limit is optional, the maximum number of array elements, the instance code is as follows:
The code is as follows:
<?php $str = "Abc|bck|fhq|nui"; Print (Explode ("|", $SRT)); Output array ([0]=>abc,[1]=>bck,[2]=>fhq,[3]=>nui)?>