在OCCASIONAL标记“ <...>”中,对某些文本进行高亮显示的最简单方法是什么?
CLARIFICATION
:我希望保留现有标签!$t = preg_replace( "/(markdown)/", "<strong>$1</strong>", "This is essentially plain text apart from a few html tags generated with some simplified markdown rules: <a href=markdown.html>[see here]</a>");
哪个显示为:
“这本质上是纯文本,除了一些用某些简化的[[markdown
规则生成的html标签之外:see here”...但是不要在锚标记(即<a href=markdown.html>
)中添加文本。我已经听说过不使用正则表达式解析html的论点,但是这里我们实质上是在谈论纯文本,除了对某些markdown代码进行最少的解析。
[在OCCASIONAL标签“
”内的文本以外的某些文本上加亮显示的最简单方法是什么?澄清:我希望保留现有标签! $ t = preg_replace(“ /(markdown)/” ......>
<?php
$item="markdown";
$t="This is essentially plain text apart from a few html tags generated
with some simplified markdown rules: <a href=markdown.html>[see here]</a>";
//_____1. apply emphasis_____
$t = preg_replace("|($item)|","<strong>$1</strong>",$t);
// "This is essentially plain text apart from a few html tags generated
// with some simplified <strong>markdown</strong> rules: <a href=
// <strong>markdown</strong>.html>[see here]</a>"
//_____2. remove emphasis if WITHIN opening and closing tag____
$t = preg_replace("|(<[^>]+?)(<strong>($item)</strong>)([^<]+?>)|","$1$3$4",$t);
// this preserves the text before ($1), after ($4)
// and inside <strong>..</strong> ($2), but without the tags ($3)
// "This is essentially plain text apart from a few html tags generated
// with some simplified <strong>markdown</strong> rules: <a href=markdown.html>
// [see here]</a>"
?>
preg_split
将字符串分成tag
preg_split()