Thestrstr()function returns the remainder of a string beginning with the first occurrence of a predefined string. Its prototype follows: string strstr(string str, string occurrence) This example uses the function in conjunction with theltrim()function to retrieve the domain name of an e-mail address: <?php This returns the following: -------------------------------------------- Returning Part of a String Based on Predefined Offsets Thesubstr()function returns the part of a string located between a predefined starting offset and length positions. Its prototype follows: string substr(string str, int start [, int length]) If the optionallengthparameter is not specified, the substring is considered to be the string starting atstartand ending at the end ofstr. There are four points to keep in mind when using this function:
Keep in mind thatstartis the offset from the first character ofstr; therefore, the returned string will actually start at character positionstart+ 1. Consider a basic example: <?php This returns the following: -------------------------------------------- The following example uses thelengthparameter: <?php This returns the following: -------------------------------------------- The final example uses a negativelengthparameter: <?php This returns the following: --------------------------------------------
blog comments powered by Disqus |
|
|
|
|
|
|
|