

#PHP SUBSTRING CODE#
strlen() might be used to check the length of user input, as in the following fragment which tests a membership code to ensure that it is exactly four digits long:Įcho "Your membership number must have 4 digits." This function requires a string as its argument, and returns an integer representing the number of characters in the string you have passed to it. You can use the built-in strlen() function to determine the length of a string. Finding the Length of a String with strlen() It is important to remember that when we talk about the position or index of a character within a string, the characters, just like array elements, have a starting index value of 0, not 1. You can think of a string as an array of characters, thus you can access the individual characters of a string as if they were elements of an array: You will have come across this word in the context of arrays, such as in Chapter 8, "Working with Arrays and Objects." In fact, strings and arrays are not as different as you might imagine. We will frequently use the word index in relation to strings.
.jpg)
PHP provides many functions that enable you to acquire information about strings.

Before you begin to work with data from an external source, you often will need to find out more about it. Strings can arrive from many sources, including user input, databases, files, and Web pages. You do not always know everything about the data that you are working with.
