How to set file pointer of second preg_match
Posted: Mon Dec 20, 2010 10:12 am
Hi there,
Suppose I have the following $subject (as .txt file) from which I have to extract two lines of data:
[text] Final Index Change(Points) Change(%)
------------ -------------- -----------
ALL SHARES PRICE INDEX (DSI) 6881.38381 -235.73029 -3.3121611
DSE - 20 INDEX (DS20) 4924.70899 -198.65431 -3.8774199
DSE GENERAL INDEX (DGEN) 8295.41835 -284.77944 -3.3190311
All Category
ISSUES ADVANCED : 51
ISSUES DECLINED : 191
ISSUES UNCHANGED : 3
TOTAL ISSUES TRADED : 245
A Category (Equity)
ISSUES ADVANCED : 16
ISSUES DECLINED : 166
ISSUES UNCHANGED : 0
TOTAL ISSUES TRADED : 182
B Category (Equity)
ISSUES ADVANCED : 4
ISSUES DECLINED : 6
ISSUES UNCHANGED : 0
TOTAL ISSUES TRADED : 10[/text]
Suppose I want to extract the value from these two lines from the above subject:
[text]ISSUES ADVANCED : 4[/text]
[text]1st preg_match:
preg_match(/^ISSUES ADVANCEd\s+:\s+(\d+)/m, $subject)[/text]
[text] TOTAL ISSUES TRADED : 182[/text]
[text]2nd preg_match:
preg_match(/^TOTAL ISSUES TRADED\s+:\s+(\d+)/m, $subject)[/text]
As you can see I have to use two different preg_match in this case, the 1st preg_match will start searching it's pattern from the starting of the subject(the .txt file) and when pattern will be matched, it will stop searching. Next the 2nd preg_match will start searching again from the starting of the subjec(.txt) file. I want that the 2nd preg_match will start searching from the place where 1st preg_match would stopped after matching it's (1st) pattern. i.e I don't want that every preg_match will start searching from the beginning of the file.
How I can set the file pointer of 2nd preg_match at the end of 1st preg_match?
Suppose I have the following $subject (as .txt file) from which I have to extract two lines of data:
[text] Final Index Change(Points) Change(%)
------------ -------------- -----------
ALL SHARES PRICE INDEX (DSI) 6881.38381 -235.73029 -3.3121611
DSE - 20 INDEX (DS20) 4924.70899 -198.65431 -3.8774199
DSE GENERAL INDEX (DGEN) 8295.41835 -284.77944 -3.3190311
All Category
ISSUES ADVANCED : 51
ISSUES DECLINED : 191
ISSUES UNCHANGED : 3
TOTAL ISSUES TRADED : 245
A Category (Equity)
ISSUES ADVANCED : 16
ISSUES DECLINED : 166
ISSUES UNCHANGED : 0
TOTAL ISSUES TRADED : 182
B Category (Equity)
ISSUES ADVANCED : 4
ISSUES DECLINED : 6
ISSUES UNCHANGED : 0
TOTAL ISSUES TRADED : 10[/text]
Suppose I want to extract the value from these two lines from the above subject:
[text]ISSUES ADVANCED : 4[/text]
[text]1st preg_match:
preg_match(/^ISSUES ADVANCEd\s+:\s+(\d+)/m, $subject)[/text]
[text] TOTAL ISSUES TRADED : 182[/text]
[text]2nd preg_match:
preg_match(/^TOTAL ISSUES TRADED\s+:\s+(\d+)/m, $subject)[/text]
As you can see I have to use two different preg_match in this case, the 1st preg_match will start searching it's pattern from the starting of the subject(the .txt file) and when pattern will be matched, it will stop searching. Next the 2nd preg_match will start searching again from the starting of the subjec(.txt) file. I want that the 2nd preg_match will start searching from the place where 1st preg_match would stopped after matching it's (1st) pattern. i.e I don't want that every preg_match will start searching from the beginning of the file.
How I can set the file pointer of 2nd preg_match at the end of 1st preg_match?