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" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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
>
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to