Created
August 25, 2021 08:47
-
-
Save mklasen/8c229fb6364787331d7948a14c3d861d to your computer and use it in GitHub Desktop.
Replacing brackets by HTML strings in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public static function process_text($text) { | |
return preg_replace_callback( | |
'/{{(.*?)\}}/', | |
function($matches) { | |
return sprintf('<span class="text-highlight">%s</span>', $matches[1]); | |
}, | |
$text | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment