Search code examples
phpregexpreg-replace-callback

PHP preg_replace_callback works on 5.3 but not on 5.2.17


i have the following code:

    return preg_replace_callback("#\{gallery: '(.+?)'(?: dir: ([0-1]))?\}#i", create_function('$i', '$dir = isset( $i[2] ) ? 1 : 0; $oGallery = new Gallery( $i[1] ) ; $oGallery->PublicSide($dir);' ), $string);

the problem is that this works on my localhost (PHP5.3) but when i upload it to my server (5.2.17) it doesnt.. any ideas why? seems to have something to do with the single quotes on "#\{gallery: '(.+?)'(?: dir: ([0-1]))?\}#i"


Solution

  • You aren't actually returning anything from your callback, so it's not going to make any replacements. Maybe you meant to do this, instead?

    ... return $oGallery->PublicSide($dir); ...