<?php function replace_text($text) { return preg_replace('/(?<!\\\\)`((?:[^`\\\\]|\\\\.)*)`/', '<code>$1</code>', $text); } $text = 'some words \` and `some code` and `some \`more code` again'; echo replace_text($text); $text = '`some words \ and `'; echo replace_text($text);
You have javascript disabled. You will not be able to edit any code.