The last element comprises the remaining string. After separating the string as per the delimiter, if the number of elements is greater than the given value, the first n-1 elements remain as it is. Positive: When the parameter has a positive value, this means that array contains this number of elements.It can be either positive, negative or zero. It specifies the number of elements of the array. NumOfElements: This is the only optional parameter.String: This is the original string that is required to be split into substrings.Whenever this element is found in the string, it marks the end of one array and the start of another. delimiter: This character is the separator which specifies the point at which the string will be split.One parameter is optional, and the other two are compulsory. The explode in PHP function accepts three parameters. However, in the second and third expression, we have passed the third parameters, and it clubs the last three substrings and removes the last substring as per the parameter value.Įxplode() Function Parameter Values and their Use In the first expression, the third parameter has not been specified, and the new array has been created with the help of the space character. In the above example, there are three expressions. Here is the code:Įxplode in PHP method breaks into array elements and returns an array of substrings or broken strings. The only necessary condition is that we take the input as a string. In such cases, we use explode in PHP method as it breaks the phone number by using a character as the delimiter. To process the input, you need to separate the area code and country code, distinguished by dash (-). You are taking user input (phone number with area code and country code) in the format: 0037 This method is also referred to as ‘split a string’ or ‘PHP split’ as it splits a string. The return type of the function is an array of strings. The primary function of explode in PHP is to break a string into an array. In this example, a space character splits the string, i.e. We will look at the use and different parameters of the explode method in the later parts of the tutorial, but first, let us look at the syntax and an example of the explode in PHP function.Īrray explode(delimeter, String, NumOfElements) Example: This function is binary-safe and returns an array of strings as a result of splitting the original string. The splitting of the string is based on a string delimiter, that is, explode in PHP function splits the string wherever the delimiter element occurs. What Is Explode in PHPĪ built-in function in PHP that splits a string into different strings is known as explode(). One such function that we are going to see today in this tutorial is explode in PHP. It offers a wide variety of built in functions. PHP is a general-purpose programming language suited for dynamic web development.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |