Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我听说这是“pre”标签的一个长期存在的问题——当您在标签内显示代码块时<pre>,您需要转义<(left尖括号) 的所有实例。
<pre>
<
是否有自动修复此问题?—(我的意思是)这样我就不必在我发布的每个帖子中手动<替换所有实例。<
<
我的建议是“自动”修复,是您放入 pre 标签的字符串上的 str_replace 。当然假设您使用 PHP,但我想每种语言都有其等价物。
<pre> <?php $str = $variable_of_stuff_going_into_pre; $str = str_replace('<', '<', $str); $str = str_replace('>', '>', $str); echo $str; ?> </pre>
这是它的一种简化版本。您也可以使用数组作为您的搜索/替换字符串。