Skip to content

Instantly share code, notes, and snippets.

@mklasen
Created August 25, 2021 08:47
Show Gist options
  • Save mklasen/8c229fb6364787331d7948a14c3d861d to your computer and use it in GitHub Desktop.
Save mklasen/8c229fb6364787331d7948a14c3d861d to your computer and use it in GitHub Desktop.
Replacing brackets by HTML strings in PHP
<?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