问题描述
我有一个大型数据库,其中包含带有<a>
标记的记录,我想删除它们.当然,有一种方法可以创建一个全选,使用strip_tags
并更新数据库的PHP脚本,但这需要很长时间.那么如何通过简单(或复杂)的MySQL查询来做到这一点?
I have a large database which contains records that have <a>
tags in them and I would like to remove them. Of course there is the method where I create a PHP script that selects all, uses strip_tags
and updates the database, but this takes a long time. So how can I do this with a simple (or complicated) MySQL query?
推荐答案
我认为,仅在MySQL中,没有任何有效的方法可以做到这一点.
I don't believe there's any efficient way to do this in MySQL alone.
MySQL确实具有REPLACE()
函数,但是它只能替换常量字符串,不能替换模式.您可能会编写一个MySQL存储函数来搜索和替换标签,但是那时候最好写一个PHP脚本来完成这项工作. 相当可能不快,但是编写起来可能会更快.
MySQL does have a REPLACE()
function, but it can only replace constant strings, not patterns. You could possibly write a MySQL stored function to search for and replace tags, but at that point you're probably better off writing a PHP script to do the job. It might not be quite as fast, but it will probably be faster to write.
这篇关于MySQL查询与PHP strip_tags等价的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!