note 67807 deleted from function.preg-match by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 01:43:07 +0000 |
| Subject: | note 67807 deleted from function.preg-match by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133076@lists.php.net to get a copy of this message | ||
Note Submitter: steve at webcommons dot biz
----
This function (for PHP 4.3.0+) uses preg_match to return the regex position (like strpos, but using
a regex pattern instead):
function preg_pos($sPattern, $sSubject, &$FoundString, $iOffset = 0) {
$FoundString = NULL;
if (preg_match($sPattern, $sSubject, $aMatches, PREG_OFFSET_CAPTURE, $iOffset) > 0) {
$FoundString = $aMatches[0][0];
return $aMatches[0][1];
}
else {
return FALSE;
}
}
It also returns the actual string found using the pattern, via $FoundString.