Tools, FAQ, Tutorials:
Splitting a String into an Array in PHP
How To Split a String into an Array of Substring in PHP?
✍: FYIcenter.com
There are two functions you can use to split a string into an Array of Substring:
Both functions will use the given criteria, substring or pattern, to find the splitting points in the string, break the string into pieces at the splitting points, and return the pieces in an array. Here is a PHP script on how to use explode() and split():
<?php $list = explode("_","php_string_function.html"); print("explode() returns:\n"); print_r($list); $list = split("[_.]","php_string_function.html"); print("split() returns:\n"); print_r($list); ?>
This script will print:
explode() returns: Array ( [0] => php [1] => string [2] => function.html ) split() returns: Array ( [0] => php [1] => string [2] => function [3] => html )
The output shows you the power of power of split() with a regular expression pattern as the splitting criteria. Pattern "[_.]" tells split() to split whenever there is a "_" or ".".
⇒ Getting Minimum/Maximum Value of an Array in PHP
⇐ Joining Array Values into a Single String in PHP
2016-12-28, 2022🔥, 0💬
Popular Posts:
Where to find tutorials on RSS specifications? I want to learn it to describe my API services. Here ...
How to add an API to an API product for internal testing on the Publisher Portal of an Azure API Man...
How to use the "Ctrl-p Ctrl-q" sequence to detach console from the TTY terminal of container's runni...
Can Multiple Paragraphs Be Included in a List Item? Yes. You can include multiple paragraphs in a si...
What is the Azure AD v1.0 OpenID Metadata Document? Azure AD v1.0 OpenID Metadata Document is an onl...