This article mainly introduces the usage analysis of substr() and explode() functions in PHP, and describes substr in detail in the form of examples. () and explode() function processing String skills are relatively frequently used functions in string operations and have certain practical value. Friends in need can refer to this article
The example describes the usage of substr() and explode() functions in PHP. Share it with everyone for your reference. The specific method is as follows:
substr(
string,start,length): This function takes out length characters from the string starting from the start position of the string. If start is a negative number, then Counting from the end of the string, if the omitted parameter length exists but is a negative number, it means that the penultimate length character is obtained. The example code is as follows:
The code is as follows:
1 2 3 4 5 6 | <?php
echo substr ( "abcdef" , 1, 3);
echo substr ( "abcdef" , -2);
echo substr ( "abcdef" , -3, 1);
echo substr ( "abcdef" , 1, -1);
?>
|
Copy after login
explode(separator,string,limit): This function splits the string into
array separator specifies where to split, string the string to be split, limit optional, the maximum number of array elements, example The code is as follows:
The code is as follows:
1 2 3 4 | <?php
$str = "abc|bck|fhq|nui" ;
print ( explode ( "|" , $srt ));
?>
|
Copy after login
The above is the detailed content of Usage of substr() and explode() functions in php. For more information, please follow other related articles on the PHP Chinese website!