Re: preg_match() occurence position
| From: | Tech Support | Date: | Thu, 25 Jul 2002 14:26:54 +0000 |
| Subject: | Re: preg_match() occurence position | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109502@lists.php.net to get a copy of this message | ||
How about this:
$text = "this is test";
preg_match can return the first match in an optional array I'll call
$matches
http://www.php.net/manual/en/function.preg-match.php
preg_match('/test/', $text, $matches);
strpos returns the numeric position of the first occurrence
http://www.php.net/manual/en/function.strpos.php
$pos = strpos($text, $matches[0]);
die("$pos"); // should be what you want... 10
Jim Grill
Support
Web-1 Hosting
http://www.web-1hosting.net
----- Original Message -----
From: "lallous" <phplist@lgwm.org>
To: <php-general@lists.php.net>
Sent: Thursday, July 25, 2002 7:40 AM
Subject: [PHP] preg_match() occurence position
> Hello,
>
> Can I get the starting position of my string occurence when using any
> regexps searching functions in PHP ?
>
> for example:
> $mem='this is a test';
> preg_match('/test/', ...) should return me somehow: 10
>
>
> Thanks
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>