Home >Backend Development >PHP Tutorial >Introduction and usage examples of the four string-related functions substr, strrchr, strstr, ereg in PHP_PHP Tutorial
1. Get part of the string.
This function extracts length characters from the start position of the string string. If start is a negative number,
is counted from the end of the string. If the omitted parameter length exists but is a negative number, it means that the length character from the bottom is obtained.
2. Get the string starting from the last occurrence of a certain character.
This function is used to find the last occurrence position of the character needle in the string haystack, and start from this position to the string
The string returned between the end of haystack. If needle is not found, false is returned.
output://localhost/test/test.php
3. Return the string from the beginning to the end of a certain string in the string.
This function returns the string from when needle first appears in haystack to the end of haystack. Returns false if needle is not found.
4. String comparison analysis.
This function uses pattern rules to parse and compare string strings. The value returned by the comparison result is placed in the array parameter regs. The content of regs[0] is the original string, regs[1] is the first string that conforms to the rules, and regs[2] is the second string that conforms to the rules. string, and so on. If the parameter regs is omitted, it will simply be compared, and the return value will be true if found.