Can I get the exact string position of a preg_match or preg_match_all matched string? I would like to check some tags around such a match (i.e. do some substr stuff) in a couple of HTML pages.
I checked the latest PHP manual. One of the possible flags for preg_match_all is PREG_OFFSET_CAPTURE, which returns the "offset value". (available from PHP 4.3.0) Unfortunately there's no example...
The manual says: "Note that this changes the return value in an array where every element is an array consisting of the matched string at offset 0 and it's string offset into subject at offset 1."
Could someone explain the meaning of "it's string offset into subject at offset 1". I'm lost.
When I run my preg_match_all looking for <a name="xxxx">something</a> tags, I get the result I want. Something like:
- $matches[0][$i] the complete match (<a name="xxxx">something</a>
- $matches[1][$i] xxxx
- $matches[2][$i] something
But how do I retrieve that offset value? And if so, is this a way to determine the position of the matched string?
thnx