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.
Javascript function below:
log.replace(/(?:<del>(.|\n)*?<\/del>)|(?:<ins>(.|\n)*?<\/ins>)/g,
function(match, p1, p2, offsetval, strval) {
//does something with the offsetval and strval
});
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.
The issue is preg_match_all supports offset capturing but not callbacks and preg_replace_callback supports callbacks but not offsets!!!
I found this function on github https://gist.github.com/hakre/5376227
Any Simpler way?
catjumps" and I need to know the offset of the match to find the position of the text inside the ins or del command. – xmxmxmx Jun 17 '18 at 09:22