How do I create an array from substrings in a text string?
Posted: Sat May 06, 2017 2:12 pm
I've been stuck on this for hours so I'm finally asking for help. I'm not sure if I'm going about this correctly but I have a text file that looks something like this:
You get the point. I've been trying to use strpos, substr, looked at preg_match but I am just really confused and lost at this point.
I want to be able to create 2 different arrays from this data.
One array like this:
And another array like this:
This way I can use foreach loops to process these arrays as needed.
Code: Select all
[Beginning]
ABC
[Ending]
[Beginning]
DEF
[Ending]
[Beginning]
GHI
[Ending]
[Beginning]
JKL
[Ending]
[Beginning]
MNO
[Ending]
I want to be able to create 2 different arrays from this data.
One array like this:
Code: Select all
$array1 = array(
"ABC",
"DEF",
"GHI",
"JKL",
"MNO"
);
And another array like this:
Code: Select all
$array2 = array(
"[Beginning]
ABC
[Ending]",
"[Beginning]
DEF
[Ending]",
"[Beginning]
GHI
[Ending]",
"[Beginning]
JKL
[Ending]",
"[Beginning]
MNO
[Ending]"
);