preg_replace -e V preg_replace_callback

Hi
I really a problem with this and would be really gratfule if somebody could help me

I have an old function that has worked fine since PHP3 - 5.xx

I find now with newly installed 7.2 it no longer works

the part in question

////[php]$body=preg_replace("/[INCLUDE]([a-z0-9;/?:@=&$-_.+!*’(),]+?)[/INCLUDE]/e",“page_inc(’\1’)”, $body);[/php]

It esentually finds text in a page($body) that contains for example [INCLUDE]SpecialMenu[/INCLUDE] and runs a function page_inc(\1) which in turn looks up the text(SpecialMenu) from a database and inserts the special menu into the page.

I think the start of my problem is the e directive and the function needs to be replaced with preg_replace_callout(…). however, as much as I try and no matter what combinations I am trying I am just not getting it.

Can anybody out there that understands the preg_replace_callout function please convert my function to a working preg_replace_callout function. I have read the php manual pages over and over but I am missing something lol. I created this function in about 2005 I think.

Cheers

Thanks in Advance

Neil

preg_replace_callout OR preg_replace_callback?

What isn’t working and where does the argument in the page_inc come from?

https://www.ideone.com/1gpvCU

Hi Astonecipher

Yes callback,callout was a typo
The argument page_inc comes from \1 which is the text value between [INCLUDE]and[/INCLUDE] within text string $body. This is the key to a database lookup for the text that will replace the string “[INCLUDE]SpecialMenu[/INCLUDE]” in $body.

Now whats not working?, well I dont know because I dont really understand how preg_replace_callback() works with regard to functions and regex like /1.

And this is the first time I have looked at this since about 2010.

Thanks Astonecipher

Cheers

I Just had a play around with your snippet Astonecipher and now have mine basically working, so thank you, I think I had over complicated it trying to use an annonymouse function within the function and did not see the wood for the trees so to speak. Man I owe you a beer or two.

Thanks Again Astonecipher

Cheers, Neil

Sponsor our Newsletter | Privacy Policy | Terms of Service