我试图获得总评论长度,但是人们可以添加列表,表格,颜色等。我只想获得实际评论字符的计数。有没有办法使用正则表达式删除除真实单词之外的所有内容来计算字符?我正在使用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
答案 0 :(得分:0)
- = - = - = - = - = - = - = - = - = - = - = - = -
这是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)