We hope you can now apply the substr() function efficiently. Now you may know how to extract characters from a String using the PHP substring function. The substring will be cut by counting 7 characters after the starting position. So, the starting position is extracted by counting from the string’s end. As you can see, here the starting position is -11, and the length is 7. This example shows how the PHP substring function is used with the positive starting position and negative length. Both the starting position and the length will count from the original string’s end and the counting will start from 1.ĥ. Use of Substring Function with Negative Starting Position and Positive Length In the following example, the starting position is -16, and the length is -9. This example shows how the PHP substring function is used with the negative starting position and length. Here, the starting position is extracted by counting from 0 to 21, and the ending position is extracted by counting 9 characters.Ĥ. Use of Substring Function with Negative Starting Position and Length In the following example, the starting position is 21, and the length is 9. This example shows how the PHP substring function is used with a positive starting position and length. When you run the script from the web server, the following output will come.ģ. Use of Substring Function with Positive Starting Position and Length The script, in this case, will return a substring from the starting position to the string’s end. As the starting position is negative, the counting startsed from the end of the string, and the value 1. This example shows how the PHP substring function is used with the negative starting position to extract a substring from a string. Use of Substring Function with Negative Starting Position When you run the script from the web server, the following output will come.Ģ. So when the starting position is 11, the string will be cut from the 12th position to the original string’s end. Below, as the starting position is positive, the counting will start from 0. This example shows how the PHP substring function is used with the positive starting position. Use of Substring Function with Positive Starting Position Now you know all the parameters used in the PHP substring function, let’s see some examples of how you can extract characters from a string using PHP substring function.ġ. How to Extract a Character From a String using PHP substring function
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |