This article describes the use of substr () and explode () functions in PHP. Share to everyone for your reference. The specific methods are as follows:
SUBSTR (string,start,length): This function extracts the length character of the string from the start of the string, and if start is a negative number, the length of the argument that can be omitted is a negative number, if it is the trailing end of the string. To take the penultimate length character, the instance code is as follows:
Copy Code code as follows:
<?php
echo substr ("abcdef", 1, 3); Return "BCD"
echo substr ("ABCdef",-2); Return to "EF"
echo substr ("ABCdef",-3, 1); Return "D"
echo substr ("abcdef", 1,-1); Return to "BCDE"
?>
Explode (separator,string,limit): This function splits a string into an array separator where the partition is divided, string to be split, limit optional, the maximum number of array elements, and the instance code is as follows:
Copy Code code as follows:
<?php
$str = "Abc|bck|fhq|nui";
Print (Explode ("|", $SRT)); Output array ([0]=>abc,[1]=>bck,[2]=>fhq,[3]=>nui)
?>
I hope this article will help you with your PHP program design.