title: Get Offset from Preg_Replace_Callback?
body: <p>I'm trying to translate my javascript which uses a javascript replace function into PHP. The js replace has a callback that uses the offset and source string values. I tried using preg_replace_callback the js replace function callback captures the offset value but PHP does not provide this. </p>
  
  <p>Javascript function below:</p>
  
  <pre><code>log.replace(/(?:&lt;del&gt;(.|\n)*?&lt;\/del&gt;)|(?:&lt;ins&gt;(.|\n)*?&lt;\/ins&gt;)/g, 
   function(match, p1, p2, offsetval, strval) {
    //does something with the offsetval and strval
   });
  </code></pre>
  
  <p>Is there any easy way to do this with preg_replace_callback or preg_match with callback? It's really just matching rather than replacing.</p>
  
  <p>The issue is preg_match_all supports offset capturing but not callbacks and preg_replace_callback supports callbacks but not offsets!!!</p>
  
  <p>I found this function on github <a href="https://gist.github.com/hakre/5376227" rel="nofollow noreferrer">https://gist.github.com/hakre/5376227</a></p>
  
  <p>Any Simpler way?</p>