what is wrong with this code:
I need to make one array from lines between the tokens: START is starting and END is ending token;
I have this type of text file:
123-456-6541 (P)
you got page one
second line
third line
END
123-456-6541 (P)
you got page one
second line
another line
END
this is php code; it supposed to keep inserting lines into array untill it reaches second token:
<?php
$fh = fopen('text2.txt','r');
while ($line = fgets($fh)) { $lines[] = $line; }
$active = false;
$temp = "";
$result = array();
for ($i = 0; $i < count ($lines); $i++ )
{
$line = $lines[$i];
if ( strpos ( $line , ' 123-456-6541 (P)' ) !== false )
{
$result[]= $line;
$active = true;
}
if (strpos($line, 'END') !== false ) {
$active = false;
}
if ($active)
$result[] = $line;
}
print_r ( $result );
Following is desired result:
Array
(
[0] => you got page one
second line
third line
[1] => you got page one
second line
another line
)
Edit: rewriting since source data example changed
This will match the phone number pattern and spit out the following: