Don't use global
here; you're already using a closure, so use the use
:
function ($m) use ($skip_books) {
// ...
}
Btw, you're not actually using $skip_books
in the code you've shown so far, but I'm assuming that's because you've simplified it
If your arguments are always numbers, don't use something generic like (.+?)
but be specific (the more the better):
/\[book=(\d+)_(\d+)\]/i
I've also removed the /s
and /m
modifiers, which are useless here.