What is the easiest way to make this PHP function so that every other backtick becomes a beginning and ending HTML tag, so that:
'in for loops, use `$index` for 0-n values and `$count` for 1-n values'
becomes:
'in for loops, use <code>$index</code> for 0-n values and <code>$count</code> for 1-n values'
e.g.
$line = 'in for loops, use `$index` for 0-n values and `$count` for 1-n values';
echo getFormattedLine($line);
function getFormattedLine($line) {
return $line; //...str_replace, regular expressions, etc.
}
Seems pretty trivial:
preg_replace('/`(.*?)`/', '<code>$1</code>', $str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With