Having lines
(01) Some text
(10) Foo Bar
(11) ?
(13) Foo Bar
(13) ?
(20) Something else
check 4 rows in a batch. If row 1 and 3 are the same and row 2 and 4 are (XX) ?, then replace rows 2-4 with ... so it results as
(01) Some text
(10) Foo Bar
...
(20) Something else
Code:
$arr = explode("\n", $t);
if ( count($arr) > 3 ) {
for ($i=1; $i<count($arr); $i++) { // check 4 rows
if( ($arr[$i-1] == $arr[$i+1]) // if row 1 and 3 are the same
&& preg_match('/\(\d+\) \?$/', $arr[$i]) // and row 2 is "(XX) ?"
&& preg_match('/\(\d+\) \?$/', $arr[$i+2]) // and row 4 is "(XX) ?"
) {
print "Match!"; //test. later replace rows 2-4 with a row "..."
}
}
}
This currently gives me an offset error.
Test: http://codepad.viper-7.com/iMO3BW
How could this be solved?
Use regex pattern
with multiline and global modifiers.
See this regex test.