开发者

Comparison of HTML and plain text from SQL

开发者 https://www.devze.com 2023-01-07 05:38 出处:网络
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 w

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 p开发者_JAVA百科asting it into notepad.


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.

SELECT * FROM YourTable
WHERE plainText = udf_stripHTML(htmlText)


The SQL doesn't know that one is HTML and one is not.

If you just want to compare the precise content, use = or LIKE.

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 (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?)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号