Substr
The function of getting substrings in PHP is substr that this function is very simple and the function prototype is as follows:
substr(string,start,length)
| Parameters |
Description |
| String |
Necessary. A string that specifies the part to return. |
| Start |
Necessary. Specifies where to start the string. Positive number-start negative at the specified position of the string-starting at the specified position starting at the end of the string 0-starts at the first character in the string |
| Length |
Optional. Specifies the length of the string to be returned. The default is until the end of the string. Positive number-length negative number returned from the position of the start parameter-length returned from the end of the string |
This is very simple. For a few examples:
<?phpecho substr("Hello world",6);?>//这个输出world
Explode
This is a string cut function, similar to the function of split.
The prototype of this function is:
explode(separator,string,limit)
| Parameters |
Description |
| Separator |
Necessary. Specifies where to split the string. |
| String |
Necessary. The string to split. |
| Limit |
Optional. Specifies the number of array elements that are returned. Possible values: greater than 0-returns an array containing a maximum of limit elements less than 0-returns an array containing all elements except the last-limit element 0-Returns an array containing an element |
The distance is as follows:
<?php$str = "Hello world. I love Shanghai!";print_r (explode(" ",$str));?>
This is: Break the string into arrays.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
PHP Learning-Get string substring