我只想对 <code> 中的内容运行 htmlentities() 以剥离 </code>
我写了一个函数,它接受一个字符串并在 <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;
}
}
但是,我需要一些有关将实际运行 htmlentities(); 的功能的帮助;在 <code> </code> 中的内容上,然后 implode() 将它们重新组合在一起。例如,假设我们有下面的字符串。
<div class="myclass" rel="stuff"> 这里的东西 </div> <code> 只在这里运行 htmlentites() 所以去掉像 < > " ' & </code> 这样的东西 <div> 里面的东西 </div>
再一次,该函数需要保持字符串的所有内容相同,但只修改和运行 <code> </code> 的内容的 htmlentities()