Results 1 to 2 of 2
Sep 14, 2011, 03:48 #1
- Join Date
- Jan 2008
- Knoxville TN
- 51 Post(s)
- 0 Thread(s)
PHP Function of the Day (2011-9-14): substr
substr returns a section of a string from another string. One of the most typical uses is to find the rest of the string after some flag character's position in the string, which itself is found using strpos.
Here's one application of the function from a larger class
The delimiter constant is "_". So, given "mypath_key" this function will return "key". Given a string that doesn't include the delimiter, the delimiter is returned directly. The +1 here assumes the delimiter is a single character - technically it should be strlen(self::DELIMITER) to not break if someone changes the delimiter to something with multiple characters.
Another example off PHP.net that returns the string between two other strings within a string using substr
Substr gets used a lot in string manipulation - Anyone else have some examples, comments, questions?