【发布时间】:2013-09-15 07:13:38
【问题描述】:
我有一个单词数组,像这样:
array("the", "over", "hen");
我也有这样的字符串:
"The quick brown fox jumps over the lazy hen"
我想在数组中所有出现的单词周围加上一个标签 (strong),但要保持大小写正确。
例如,使用前面的字符串,它会结束
<strong>The</strong> quick brown fox jumps <strong>over</strong the lazy <strong>hen</strong>
但是,如果我有这句话:
"Hen #2 and ThE oveR reactive cow"
看起来像这样:
<strong>Hen</strong> #2 and <strong>ThE</strong> <strong>oveR</strong> reactive cow
我猜答案会使用正则表达式,但我不太擅长...
【问题讨论】:
-
您是否尝试在比较过程中仅转换为小写,然后使用原始标签替换/包围您的标签?
-
@Fluffeh 你是什么意思?你能举一个我怎么做的例子吗?