The easiest way to get this text into an array like you describe would be:
preg_match_all('/.+/',$string, $array);
Since /./
matches any char, except for line terminators, and the +
is greedy, it'll match as many chars as possible, until a new-line is encountered.
Using preg_match_all
ensures this is repeated for each line, too. When I tried this, the output looked like this:
array (
0 =>
array (
0 => '$test = \'Test This is first line',
1 => 'Test:123',
2 => 'This is Test\';',
),
)
Also note that line-feeds are different, depending on the environment (\n
for *NIX systems, compared to \r\n
for windows, or in some cases a simple \r
). Perhaps you might want to try explode(PHP_EOL, $text);
, too