nackle2k10 — 2013-07-28T14:07:03-04:00 — #1
Hi, I'm trying to turn input from textarea into an array
here is what the textarea input look like
[input 1] [input 2] [input 3]
I'm trying to split everything inside the square bracket "" into an array.
here are my codes
$option = array();
$regex = "#[\\[^]]*#s";
$input = "[input 1] [input 2] [input 3]";
$option = preg_split($regex, $input, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
the output is
 => input 1]
 => input 2]
 => input 3]
the closing bracket still there, So what am I missing the regex pattern? Thanks
parkint — 2013-07-28T14:23:08-04:00 — #2
I think you can avoid RegExp all together.
Use explode instead.
You should trim leading and trailing square brackets first with:
$option = explode("] [", trim($input, ""));
nackle2k10 — 2013-07-28T14:38:13-04:00 — #3
This is a good way to create the array but since the input is inputted using texarea I cannot take control of the input it may be have enter or space between each bracket   are there any solutions?
nackle2k10 — 2013-07-29T03:23:04-04:00 — #4
Hi, I have solve this by using this regex