I want to run htmlentities() only on the contents within <code> things to strip </code>
I Wrote a function that takes a string and finds the content in between <code> </code>
function parse_code($string) {
// test the string and find contents with <code></code>
preg_match('@<code>(.*?)</code>@s', $string, $matches);
// return the match if it succeeded
if($matches) {
return $matches[1];
}else {
return false;
}
}
However I need some help with a function that will will actually run htmlentities(); on the contents within <code> </code> and then implode() it all back together. For example lets say we have the string below.
<div class="myclass" rel="stuff"> things in here </div> <code> only run htmlentites() here so strip out things like < > " ' & </code> <div> things in here </div>
Once again, The function would need to keep all contents of the string the same but only modify and run htmlentities() on the contents of <code> </code>