【发布时间】:2012-10-15 15:30:58
【问题描述】:
我有类似<code> <1> <2> </code> 的东西,我想得到这个:<code> &lt;1&gt; &lt;2&gt; </code> 但我只想在<code></code> 标签内应用它,而不是其他任何地方。
我已经有了这个:
$txt = $this->input->post('field');
$patterns = array(
"other stuff to find", "/<code>.*(<).*<\/code>/m"
);
$replacements = array(
"other stuff to replace", "<"
);
$records = preg_replace($patterns,$replacements, $txt);
它成功替换了字符但它删除了包围的<code></code>标签
任何帮助将不胜感激!谢谢
【问题讨论】:
-
你考虑过使用 DOM 解析器吗?
-
我需要在php中做这个
-
@user990463 - PHP 包含一个 DOM 解析器 - 请参阅 php.net/manual/en/class.domdocument.php
-
使用 PHPs DOMDocument 类。