python72 Posted January 7, 2011 Share Posted January 7, 2011 I have noticed that if I run the preg_match_all function and use PREG_OFFSET_CAPTURE option to start capture somwhere in the middle of the string the second half of the string will be searched first returning the matching sections along with positions, then it goes up to the top half and returns matches from there too. Is there way to parse only between start point and end of string? Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 7, 2011 Share Posted January 7, 2011 PREG_OFFSET_CAPTURE doesn't start in the middle of the string, it stores the offset, in the array, of each matched section. You can pass the function an offset as it's fourth argument. But, this is evaluated in bytes, and wouldn't be the same as passing it part of the string using the substr() function. It is explained here Quote Link to comment Share on other sites More sharing options...
python72 Posted January 7, 2011 Author Share Posted January 7, 2011 Well, I guess I did not understand the PREG_OFFSET_CAPTURE. I am passing $offset as the fourth argument though and it seems that first preg_match_all starts at the $offset and goes to the end of the string, then goes to the start of the string and searches till the $offset position. Is it the way it is supposed to happen or am I doing something wrong? Quote Link to comment Share on other sites More sharing options...
python72 Posted January 7, 2011 Author Share Posted January 7, 2011 Just to clarify here is my code: $Pattern='/[\d]{2} [\d]{2} [\d]{2} [\d]{2} [\d]{2} [\d]{2} [\d]{2}/'; $SetNumber=preg_match_all($Pattern, $Page, $Matches, PREG_OFFSET_CAPTURE, $NumberPosition); Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 7, 2011 Share Posted January 7, 2011 You may need to pass part of the string to the function. As the offset counts in bytes, which includes part of the pattern. I would use: $SetNumber = preg_match_all($Pattern,substr($Page,$NumberPosition),$Matches, PREG_OFFSET_CAPTURE); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.