Read a block of text from file delimited by string as a record delimited
The delimiter can either be prefixed, suffixed - or removed
Given the data:
01
02
###
04
05
###
07
08
$delimiter = '###';
$direction = -1; // Default: prefixed
$fp = @fopen("readTextBlock.txt", "r");
while( $record = get_text_block( $fp, $delimiter, $direction ) ) // Get each record
{
echo "[$record]\n";
}
fclose($fp);
Output:
Delimiter will be at the end of record (Suffixed)
[01 02 ### ]
[04 05 ### ]
[07 08 ]
Delimiter will be removed from record
[01 02 ]
[04 05 ]
[07 08 ]
Delimiter will be at the start of record (Prefixed)
[01 02 ]
[### 04 05 ]
[### 07 08 ]