Can I somehow know which replacement is taking place from within a callback of preg_replace_callback
Posted
by jayarjo
on Stack Overflow
See other posts from Stack Overflow
or by jayarjo
Published on 2010-03-20T09:18:01Z
Indexed on
2010/03/20
9:21 UTC
Read the original article
Hit count: 320
php
|preg-replace-callback
I'm using preg_replace_callback to substitute particular tokens within the string. But apart from actual token I need to know as well whether that token was first, second or third in a subject string. Is there any way to access that info?
I found an argument $count in preg_replace_callback definition (http://php.net/manual/en/function.preg-replace-callback.php), which counts replacements, but I'm not sure if it is accessible from within callback. Any example of the usage in described context?
© Stack Overflow or respective owner