$string = "Lorem Ipsum is #simply# dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard #dummy# text ever since the 1500s, when an unknown printer took a galley of #type1# and scrambled it to #make# a #type2# specimen book. It has survived not only #five# centuries, but also the #leap# into electronic typesetting, remaining essentially unchanged";
我有一组硬编码词,比如"#simply# | #dummy# | #five# | #type1#"
我期望的输出是:
如果在其中找到硬代码字
$string
,则应以黑色突出显示。喜欢"<strong>...</strong>"
。如果一个单词在
$string
其中#...#
但在硬编码单词列表中不可用,那么字符串中的那些单词应该以红色突出显示。请注意,即使我们有 #type1# 硬代码字,如果 $string 包含
#type2#
或#type3#
它也应该突出显示。
为此,我尝试如下
$pattern = "/#(\w+)#/";
$replacement = '<strong>$1</strong>';
$new_string = preg_replace($pattern, $replacement, $string);
这让我在 #..# 标记中突出显示的所有单词。
我在preg_不好有人可以帮忙。提前致谢。