I’m using this method:
$matches;
preg_match('/^days:\s(.*)$/', $line, $matches);
if (count($matches) > 1)
return explode('; ', $matches[1]);
return array();
On a file with lines like:
days: Monday; Thursday; Friday,
And the first result (in the example, Monday), always comes with the “days:” part added on, like this:
array[0](
myObject=>object
(
visitors[0]=>array //notice "visitors" is the problem. It should be "days".
(
[0]=>days: Monday
[1]=>Thursday
[2]=>Friday
)
)
)
I thought regex was supposed to return what’s inside the brackets (())?
As nickb pointed out, your code seems to run just fine. Perhaps when you hand-wrote it in you actually fixed an issue that’s in production code. Or the bug you are seeing may be a result of something else that’s happening in another part of your code.
This is what I get when I run