RE: [PHP] how can i lookup the index in a string where a regexp matches?
| From: | Boyd, Todd M. | Date: | Tue, 18 Nov 2008 14:50:51 +0000 |
| Subject: | RE: [PHP] how can i lookup the index in a string where a regexp matches? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-283453@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Rene Veerman [mailto:rene7705@gmail.com]
> Sent: Tuesday, November 18, 2008 8:47 AM
> To: php php
> Subject: [PHP] how can i lookup the index in a string where a regexp
> matches?
>
> hi, i need to search with regexps in strings, and want to know the
> index
> (of the source string) at which the regexp matched. and the length of
> the matched string, so with substitutions like \d+..
>
> i'm kinda in a hurry on this one, would appreciate your immediate
> answer
> very much..
From http://www.php.net/preg_match :
flags
flags can be the following flag:
PREG_OFFSET_CAPTURE
If this flag is passed, for every occurring match the appendant
string offset will also be returned. Note that this changes the return
value in an array where every element is an array consisting of the
matched string at index 0 and its string offset into subject at index 1.
HTH,
// Todd