0

我试图获得总评论长度,但允许人们添加列表、表格、颜色等。我只想获得实际评论字符的数量。有没有办法使用正则表达式去除除真实单词以外的所有内容来计算字符?我正在使用 mySQL 5.5,这是我当前的查询:

select sum(COALESCE(length(reviewTxt),0) + COALESCE(length(reviewTxt1),0) + COALESCE(length(reviewTxt2),0) + COALESCE(length(reviewTxt3),0) + COALESCE(length(reviewTxt4),0) + COALESCE(length(reviewTxt5),0) + COALESCE(length(reviewTxt6),0) + COALESCE(length(reviewTxt7),0) + COALESCE(length(reviewTxt8),0) + COALESCE(length(reviewTxt9),0) + COALESCE(length(reviewTxt10),0)) as totalLength
                    from set_reviews
4

1 回答 1

0

以下内容取自http://www.sitepoint.com/forums/showthread.php?656167-PHP-s-strip_tags%28%29-equivalent-MYSQL-function

-=-=-=-=-=-=-=-=-=-=-=-=-

这是 php 函数 strip_tags

delimiter ||

DROP FUNCTION IF EXISTS strip_tags||
CREATE FUNCTION strip_tags( x longtext) RETURNS longtext
LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA
BEGIN
DECLARE sstart INT UNSIGNED;
DECLARE ends INT UNSIGNED;
SET sstart = LOCATE('<', x, 1);
REPEAT
SET ends = LOCATE('>', x, sstart);
SET x = CONCAT(SUBSTRING( x, 1 ,sstart -1) ,SUBSTRING(x, ends +1 )) ;
SET sstart = LOCATE('<', x, 1);
UNTIL sstart < 1 END REPEAT;
return x;
END;
||
delimiter ;

mysql> SELECT strip_tags('<a href="HelloWorld.html"><B>Hi, mate!</B></a>') as strip_tags;

+------------+
| strip_tags |
+------------+
| Hi, mate!  |
+------------+

1 row in set (0.00 sec)
于 2013-04-25T16:35:43.847 回答