Anman Posted October 20, 2009 Share Posted October 20, 2009 Hey, I'm trying to create a syntax highlighter plugin using GeSHi. My only problem is this: preg_replace('#\[code=(.*?)\](.*?)\[/code\]#i', "<div class='codeblock'>" . geshify("$1", "$2") . "</div>", $message); In particular: geshify("$1", "$2") The problem is it's passing literally dollar sign 1 and 2 (respectively) to the function, not the replacement. I would greatly appreciate any help regarding this matter.[/code] Link to comment https://forums.phpfreaks.com/topic/178396-preg_replace-help/ Share on other sites More sharing options...
thebadbad Posted October 20, 2009 Share Posted October 20, 2009 If you want to run the function and use its output in the replacement, you would have to use preg_replace_callback() e.g.: <?php $message = preg_replace_callback( '#\[code=(.*?)\](.*?)\[/code\]#i', create_function( '$matches', 'return \'<div class="codeblock">\' . geshify($matches[1], $matches[2]) . \'</div>\';' ), $message ); ?> Link to comment https://forums.phpfreaks.com/topic/178396-preg_replace-help/#findComment-940773 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.