jumpfroggy Posted May 5, 2008 Share Posted May 5, 2008 I have a $subject, and a regular-expression search string $pattern. I want to find the position of the first match of $pattern in $subject. Basically, I want a strpos() that works with regular expressions. If I do preg_match($pattern, $subject), it will return 0 (for no match) or 1 (for match found), but no position. If I do preg_match($pattern, $subject, $matches), then I'll get an array of matches in $matches, but no positions. Is there any way to do this? Thanks! Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 5, 2008 Share Posted May 5, 2008 Tried looking in the manual? The 4th parameter is what you need. Quote Link to comment Share on other sites More sharing options...
jumpfroggy Posted May 5, 2008 Author Share Posted May 5, 2008 Tried looking in the manual? The 4th parameter is what you need. Thanks for catching that, I looked at the pages for each of the preg_* functions a few times, managed to gloss over that one key line. Stupid of me. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.