Jump to content

nackle2k10

New Members
  • Posts

    2
  • Joined

  • Last visited

nackle2k10's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. @grumpy the reason why I don't use trim() to strip the "[" and "]" is the input are not handled by me, so user may use enter when inputing the option or not even use space at all. The solution I use is this pattern $regex = "#\[|\]\s+|[\]]#s"; $input = "[input 1] [input 2] [input 3]"; $option = preg_split($regex, $input, -1, PREG_SPLIT_NO_EMPTY); what do you guys think? Does this pattern is the best practice? Btw, what happen to this forum yesterday? I tried to visit it few times and got 404 error.
  2. 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 Array ( [0] => input 1] [1] => input 2] [2] => input 3] ) the closing bracket still there, So what am I missing in the regex pattern? Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.