HTML 和 SQL 纯文本的比较
有两列。其中一个包含 HTML,另一个包含纯文本。我如何将它们作为两个纯文本进行比较?转换 HTML ->纯文本的处理方式应与浏览器将选定的 HTML 复制到剪贴板并将其粘贴到记事本时的处理方式相同。
There are two columns. One of them contains HTML and another contains plain text. How can I compare them as 2 plain texts? Converting HTML -> plain text should be done the same way as a browser does when copying selected HTML into clipboard and pasting it into notepad.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这个问题的答案 链接到用户定义的函数,用于从文本中剥离 HTML 标签。完成此操作后,您可以与纯文本字段进行比较,例如
The answer to this SO question links to a user-defined function for stripping HTML tags from text. After doing this you can then compare with the plain text field, e.g.
SQL 不知道一种是 HTML,另一种不是。
如果您只想比较精确的内容,请使用
=
或LIKE
。如果您想删除标签,请准确执行...从 HTML 列中删除标签,然后将其结果与 SQL 列进行比较。
The SQL doesn't know that one is HTML and one is not.
If you just want to compare the precise content, use
=
orLIKE
.If you want to remove the tags, do precisely that... remove the tags from the HTML column, and then compare the result of that to the SQL column.
当您从数据库中提取值时,它们是您的字段包含的任何数据类型。您可以用您想要的编程语言以任何您想要的方式操作字符串......(如果它们本来就是文本,它们应该已经是文本)。
When you pull the values from the database they are whatever datatype your field containes. You can manipulate the strings any way you want in your desired programming language.... (they should already be text if that is what they were).
SQL 2008(及更早版本)不包含任何可以“本机”将 HTML 转换为非 HTML 的函数或代码。您要么需要自己编写这样的函数,要么找到可以执行此操作的第三方实用程序。 (是否有执行此操作的应用程序代码?也许读取数据并通过该应用程序运行它?)
SQL 2008 (and earlier) does not contain any function or code that can "natively" convert HTML into, err, non-HTML. You either need to write such a function yourself, or find a third-party utility that can do this. (Is there application code that does this? Perhaps read the data and run it through that app?)