- preg_replace: documentation ( source)
<?php
function format_text($string) {
$string = preg_replace('/(\*\*(.*?)\*\*)/', '<b>\\2</b>', $string);
$string = preg_replace('/(##(.*?)##)/', '<em>\\2</em>', $string);
return $string;
}
$before = "Focus on the **user** and all else will ##follow##.";
$after = format_text($before);
echo $after;