13.10.3. Discussion
This breaks apart a numbered list and places the individual list
items into array elements. So, if you have a list like this:
1) Gödel
2) Escher
3) Bach
You end up with a four-element array, with an empty opening element.
That's because preg_split( )
assumes the delimiters are between items, but in this case, the
numbers are before items:
Array
(
[0] =>
[1] => Gödel
[2] => Escher
[3] => Bach
)
From one point of view, this can be a feature, not a bug, since the
nth element holds the nth
item. But, to compact the array, you can eliminate the first element:
$records = preg_split('/[0-9]+\) /', $contents);
array_shift($records);
Another modification you might want is to strip new lines from the
elements and substitute the empty string instead:
$records = preg_split('/[0-9]+\) /', str_replace("\n",'',$contents));
array_shift($records);