Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个普通的 bbCode 函数,例如在我的帖子中搜索[b]并[/b]用粗体文本替换它们。当访问者在我的博客上搜索某个帖子时,他或她可能会搜索图像的文件名 ( [img]path/to/image.jpg[/img])。如果发生这种情况,由于突出显示,图像将从帖子中消失。
[b]
[/b]
[img]path/to/image.jpg[/img]
我怎样才能让搜索引擎(这是一个常规的WHERE column LIKE '%string%')不在我的 bbCodes 中搜索?
WHERE column LIKE '%string%'
提前致谢。
您可以添加另一个子句来排除某些标签:
WHERE column LIKE '%string%' AND column NOT LIKE '%[img]%[/img]%'
请注意,这样做会排除所有带有 [img] 标签的结果,即使您可能需要考虑其他标签。由于这可能不是您真正想要的,因此您应该保持查询不变,并使用 PHP 中的正则表达式进行替换。