- preg_replace: documentation ( source)
<?php
function replace_text($text) {
return preg_replace(array('/(?<!\\\\)`((?:[^`\\\\]|\\\\.)*)`/', '/\\\\`/'), array('<code>$1</code>', '`'), $text);
}
$text = 'some words \` and `some code` and `some \`more code` again';
echo replace_text($text);