* luci/libs: add striptags() to luci.util
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 20 Aug 2008 16:40:25 +0000 (16:40 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 20 Aug 2008 16:40:25 +0000 (16:40 +0000)
libs/core/luasrc/util.lua

index c6d9ec6..66e3682 100644 (file)
@@ -208,6 +208,13 @@ function pcdata(value)
        return value:gsub(">", "&gt;")
 end
 
+--- Strip HTML tags from given string.
+-- @param value        String containing the HTML text
+-- @return     String with HTML tags stripped of
+function striptags(s)
+       return (s:gsub("</?[A-Za-z][A-Za-z0-9:_%-]*[^>]*>", " "):gsub("%s+", " "))
+end
+
 --- Splits given string on a defined separator sequence and return a table
 -- containing the resulting substrings. The optional max parameter specifies
 -- the number of bytes to process, regardless of the actual length of the given