Title: preg_replace_callback not working
Last modified: August 5, 2020

---

# preg_replace_callback not working

 *  [phaedracasadio](https://wordpress.org/support/users/phaedracasadio/)
 * (@phaedracasadio)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/preg_replace_callback-not-working/)
 * I’ve a problem inside my block frontend code (php)
 * In this case ‘query’ attribute is ‘AUTH:{AUTH}’
 * <?php
    $query = $attributes[‘query’]; $q = preg_replace_callback(‘/{(\w+)}/’,
   function($matches) { return $matches[1]; }, $query); echo ‘<div>’.$q.'</div>’;}?
   >
 * This code is not working.
    I tried the above code in more than one php playground
   and it’s working correctly. The result to the above snippet must be that $q is‘
   AUTH:AUTH’. This is a simplified case, the above inline function must return 
   a more complex value.
 * Thanks.

Viewing 1 replies (of 1 total)

 *  Plugin Author [nK](https://wordpress.org/support/users/nko/)
 * (@nko)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/preg_replace_callback-not-working/#post-13236838)
 * Hi.
 * I think the problem in the eval PHP function ([https://www.php.net/manual/en/function.eval.php](https://www.php.net/manual/en/function.eval.php)).
   We use it to output the custom block code.
 * In your case better to use PHP callbacks to output code – [https://lazyblocks.com/documentation/blocks-code/php-callback/](https://lazyblocks.com/documentation/blocks-code/php-callback/)
 * Regards, nK.

Viewing 1 replies (of 1 total)

The topic ‘preg_replace_callback not working’ is closed to new replies.

 * ![](https://ps.w.org/lazy-blocks/assets/icon-256x256.png?rev=2584676)
 * [Custom Block Builder - Lazy Blocks](https://wordpress.org/plugins/lazy-blocks/)
 * [Support Threads](https://wordpress.org/support/plugin/lazy-blocks/)
 * [Active Topics](https://wordpress.org/support/plugin/lazy-blocks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/lazy-blocks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/lazy-blocks/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [nK](https://wordpress.org/support/users/nko/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/preg_replace_callback-not-working/#post-13236838)
 * Status: not resolved