PHP: explode()
Explode() is designed to split a given string in to pieces at a defined point (another string).
PHP Explode() Prototype
Array: This array will contain each piece of the string after it has been split.
Separator: Whenever this string is encountered in the target string, the target string will be split into two pieces, using the separator as the middle point. The separator itself is discarded.
Limit: This is optional. After this many splits have been done, the rest of the string is placed in the last element of the array. Alternatively, if this is a negative number, e.g -x, then all but the last x splits will be performed.
How to Use Explode() in PHP
Let's say we have a list of names, each separated by a ""
To use these names in a meaningful way, we should first separate them into an array ($namearray), using explode():
The end result:
Comment:
it should be
$namearray = explode(";", $names);
and not
$namearray = explode($names, ";");
!!!
$data = "john\tboston"; // I assume \t inserts a TAB character
I want to get $name = "john" and $city = "boston"
$data = "john\tboston"; // I assume \t inserts a TAB character
I want to get $name = "john" and $city = "boston"
answer: write
list($name,$city) = explode("\t",$data)
$var=explode(" "|"/n",$text);
or something?
ok
$arr = explode("t", $line);
Now ive seen everythign
how about if i hv data smthg like this (from a file, separated by tab and n):
A1 A2 A3 A4
B1 B2 B3 B4
how to explode into 2-dimensional array?