Tools, FAQ, Tutorials:
Splitting a String in PHP
How To Split a String into Pieces?
✍: FYIcenter.com
There are two functions you can use to split a string into pieces:
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 ".".
⇒ Joining Multiple Strings in PHP
⇐ Converting Character to ASCII Value in PHP
2016-10-13, ∼2461🔥, 0💬
Popular Posts:
Why I am getting "LNK1104: cannot open file 'MSCOREE.lib'" error when building a C++/CLI program? Vi...
How to access Query String parameters from "context.Request.Url.Que ry"object in Azure API Policy? Q...
How To Move Uploaded Files To Permanent Directory in PHP? PHP stores uploaded files in a temporary d...
How to add request body examples to my Azure API operation to make it more user friendly? If you hav...
How To Pass Arrays By References? in PHP? Like normal variables, you can pass an array by reference ...