如何从SQL Server中的字符串中剥离HTML标记? [英] How to strip HTML tags from a string in SQL Server?

查看:158
本文介绍了如何从SQL Server中的字符串中剥离HTML标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server 2005中有包含HTML标记的数据,我想将所有内容剥离掉,只在标记之间保留文本.理想情况下,也可以将&lt;之类的内容替换为<等.

I've got data in SQL Server 2005 that contains HTML tags and I'd like to strip all that out, leaving just the text between the tags. Ideally also replacing things like &lt; with <, etc.

是否有一种简单的方法来执行此操作,或者有人已经获得了一些示例T-SQL代码?

Is there an easy way to do this or has someone already got some sample T-SQL code?

我没有添加扩展存储的proc之类的功能,因此更喜欢纯T-SQL方法(最好是一种与SQL 2000向后兼容的方法).

I don't have the ability to add extended stored procs and the like, so would prefer a pure T-SQL approach (preferably one backwards compatible with SQL 2000).

我只想使用剥离的HTML来检索数据,而不是对其进行更新,因此理想情况下,它将被编写为用户定义的函数,以方便重用.

I just want to retrieve the data with stripped out HTML, not update it, so ideally it would be written as a user-defined function, to make for easy reuse.

例如,将其转换为

<B>Some useful text</B>&nbsp;
<A onclick="return openInfo(this)"
   href="http://there.com/3ce984e88d0531bac5349"
   target=globalhelp>
   <IMG title="Source Description" height=15 alt="Source Description" 
        src="/ri/new_info.gif" width=15 align=top border=0>
</A>&gt;&nbsp;<b>more text</b></TD></TR>

对此:

Some useful text > more text

推荐答案

有一个UDF将执行以下操作:

There is a UDF that will do that described here:

请注意,这是针对SQL Server 2005的,但是如果将关键字MAX更改为4000,则它也可以在SQL Server 2000中使用.

note this is for SQL Server 2005, but if you change the keyword MAX to something like 4000, it will work in SQL Server 2000 as well.

这篇关于如何从SQL Server中的字符串中剥离HTML标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆