Easiest way to convert backlinks to '<code>' and '</code>'?

What is the easiest way to make this PHP function so that every other backtick becomes the beginning and end of the 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' 

eg.

 $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. } 
+4
source share
1 answer

Seems pretty trivial:

 preg_replace('/`(.*?)`/', '<code>$1</code>', $str); 
+10
source

All Articles