I am doing some tests moving from the function split to preg_split in this line of code
list($tag) = preg_split('/[ >]/', substr($chunk, 2 - $open), 2);
What exactly do the []
do? Can they be omitted?
I am doing some tests moving from the function split to preg_split in this line of code
list($tag) = preg_split('/[ >]/', substr($chunk, 2 - $open), 2);
What exactly do the []
do? Can they be omitted?
It allows any character in the set. That is the use of []
in RegEx (Regular Expressions).
Eg: /[ABC]/
will match any capital letter of "A", "B" or "C".
Take a look at some information at http://www.regexr.com/. That should help a lot. It also allows you to see what will be picked up by testing your own search text with expressions.
The []
chars define an char group. Any character in this group would be allowed.
So your code /[ >]/
allow a space or the
>
char. The /
chars surround the regex expression.
=> Your regex split the input on every or
>