 Site Admin
Joined: 10 Dec 2007 Posts: 143 Location: New Zealand
|
I spent awful a lot of time to work with simple preg_match_all using regex pattern.
I had a fairly big text file (around 1 MB text file) and I tried to work with some patterns that reads multiple lines and extract data out of those pattern.
The sample was something like below:
| Code: | <data>
xxxx
xxxxxxxxxx
...
</data>
<data>
xxxx
xxxxxxxxxx
...
</data>
(about 1 MB length in total for 2 values)
|
and I was trying to extract values out of data using the following PHP code:
| Code: | $data = array();
preg_match_all("%<data+>(.*?)</data+>%s",$input_text,$data,PREG_SET_ORDER); |
RESULT SHOULD BE:
| Code: | Array
(
[0] => Array
(
[0] => <data>
data1
xxxxxxxxxx
...
</data>
[1] =>
data1
xxxxxxxxxx
...
)
[1] => Array
(
[0] => <data>
data2
xxxxxxxxxx
...
</data>
[1] =>
data2
xxxxxxxxxx
...
)
) |
BUT the problem was it WASN'T extracting values correctly.
So I spent hours to figure it out and tried all sorts of different combinations to make work without success.
At the end, I found an article about pcre.backtrack_limit and pcre.recursion_limit and that article told me increasing these limit will fix my problem and finally I got it working.
If you have the same problem, do with following steps:
1. Open php.ini
2. Find pcre.backtrack_limit and pcre.recursion_limit and change the limit.
3. Save php.ini
4. Restart web server if necessary
http://docs.php.net/manual/en/pcre.configuration.php _________________ Paul KH Kim
http://www.onlinesolution.co.nz |
|