对于给定的字符串(通常是一个段落),我想替换一些单词/短语,但如果它们碰巧以某种方式被标签包围,则忽略它们。这也需要不区分大小写。
以此为例:
You can find a link here link and a lot of things in different styles. Public platform can appear in bold: public platform, and we also have italics here too: italics. While I like soft pillows I am picky about soft pillows. While I want to find fox, I din't want foxes to show up. The text "shiny fruits" is in a span tag: one of the shiny fruits.
假设我想替换这些词:
link:出现 2 次。第一个是纯文本(匹配),第二个是 A 标记(忽略)公共平台:纯文本(匹配,不区分大小写),B 标记中的第二个(忽略)softpillows:1 个纯文本匹配。fox:1 个纯文本匹配。它查看完整的单词。fruits:纯文本(匹配),span 标记中的第二个(忽略)与其他文本作为背景;我正在搜索短语匹配(不是单个单词)并将匹配链接到相关页面。
我想避免嵌套 HTML(粗体标签内没有链接,反之亦然)或其他错误(例如:the phrase goes a> 这里)
我尝试了几种方法,例如搜索已删除 HTML 内容的经过清理的文本副本,虽然这告诉我存在匹配项,但我遇到了将其映射回原始内容的全新问题。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号