Php explode1/23/2024 While you need to separate the country and area code that are separated by dashes. For example, your web form is taking the phone number with country and area code in this format: The explode method is also searched as “PHP split” or split a string, which is used to split the given strings. The total count of the array element is also 5 rather 10 as in the above example. You can see the demo page, only five substrings are displayed while the last substring is the remaining substring of the given string. This time, we specified 5 splits by using the limit parameter. “This is explode tutorial that enables string split in PHP”Īs it returned total ten substrings while space delimiter was used. This is the same example as above except we used the limit parameter to specify the number of splits in the string. See online demo and code An example with the limit parameter See example and output by the image or link below: A foreach loop to display the returned array elements is used.įinally, we used the count function to display the total number of substrings or elements in that array. After creating the string, the PHP explode method is used to split that string. This is explode tutorial that enables string split in PHPĪgain, we did not use the limit parameter in that example. In this example, we used the space delimiter. See online demo and code An example with space delimiter See the demo and code by clicking the following image or link: As there is no limit parameter, the whole phone number will be broken in three substrings. The returned array is assigned to an array.įinally, we used a foreach loop to display the array element values that are split substrings of the phone number string. ![]() ![]() In the following example, we have declared a string variable and assigned it a phone number in this format:Īfter that, the explode method is used to split a string by using the hyphen (dash) delimiter. $array_name = explode ( $delimiter, $string_to_split, $no_of_breaks )Īn explode example to split phone numbers
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |