我正在使用PHP进行SEO项目,并希望突出显示HTML内容中的特定单词。修改需要在特定标记上,即<p>
标记,而不是其他标记。标题标签(<h1>
,<h2>
等)
另外,如果任何HTML标记属性包含要替换的特定单词,我希望不会影响它。
<h1>A **SPECIFIC_WORD** information</h1> <p><img src="some_image.jpg" title="**SPECIFIC_WORD** some other words" /> 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 type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining <a href="#" title="some other words **SPECIFIC_WORD** other words">essentially unchanged</a>. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently **SPECIFIC_WORD** with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
如您所见,SPECIFIC_WORD出现在很多地方,但我想匹配并修改段落文本中的SPECIFIC_WORD,而不是任何标签属性或标题标签。
答案 0 :(得分:0)
使用" **SPECIFIC_WORD** "
的正则表达式。不是"**SPECIFIC_WORD**"
小心保持空间和在**SPECIFIC_WORD**
之后