{"id":434,"date":"2007-11-07T00:00:00","date_gmt":"2007-11-06T16:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=434"},"modified":"2011-07-15T09:56:13","modified_gmt":"2011-07-15T01:56:13","slug":"removing-html-tags-using-mysql","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=434","title":{"rendered":"Removing HTML tags using mysql"},"content":{"rendered":"<p><P>Try this (ported from a T-SQL func by Robert Davis): <\/P><br \/>\n<P>SET GLOBAL log_bin_trust_function_creators=1;<BR>DROP FUNCTION IF EXISTS fnStripTags;<BR>DELIMITER |<BR>CREATE FUNCTION fnStripTags( Dirty varchar(4000) )<BR>RETURNS varchar(4000)<BR>DETERMINISTIC <BR>BEGIN<BR>&nbsp; DECLARE iStart, iEnd, iLength int;<BR>&nbsp;&nbsp;&nbsp; WHILE Locate( &#8216;&lt;&#8216;, Dirty ) &gt; 0 And Locate( &#8216;&gt;&#8217;, Dirty, Locate( &#8216;&lt;&#8216;, Dirty )) &gt; 0 DO<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BEGIN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SET iStart = Locate( &#8216;&lt;&#8216;, Dirty ), iEnd = Locate( &#8216;&gt;&#8217;, Dirty, Locate(&#8216;&lt;&#8216;, Dirty ));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SET iLength = ( iEnd &#8211; iStart) + 1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IF iLength &gt; 0 THEN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BEGIN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SET Dirty = Insert( Dirty, iStart, iLength, &#8221;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END IF;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END;<BR>&nbsp;&nbsp;&nbsp; END WHILE;<BR>&nbsp;&nbsp;&nbsp; RETURN Dirty;<BR>END;<BR>|<BR>DELIMITER ;<BR>SELECT fnStripTags(&#8216;this &lt;html&gt;is &lt;b&gt;a test&lt;\/b&gt;, nothing more&lt;\/html&gt;&#8217;);<BR><\/P><br \/>\n<DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Try this (ported from a T-SQL func by Robert Davis): SET GLOBAL log_bin_trust_function_creators=1;DROP FUNCTION IF EXISTS fnStripTags;DELIMITER |CREATE FUNCTION fnStripTags( Dirty varchar(4000) )RETURNS varchar(4000)DETERMINISTIC BEGIN&nbsp; DECLARE iStart, iEnd, iLength int;&nbsp;&nbsp;&nbsp; WHILE Locate( &#8216;&lt;&#8216;, Dirty ) &gt; 0 And Locate( &#8216;&gt;&#8217;, Dirty, Locate( &#8216;&lt;&#8216;, Dirty )) &gt; 0 DO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BEGIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SET iStart = Locate( &#8216;&lt;&#8216;, Dirty &hellip; <a href=\"https:\/\/www.strongd.net\/?p=434\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Removing HTML tags using mysql<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[203],"class_list":["post-434","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=434"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/434\/revisions"}],"predecessor-version":[{"id":942,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/434\/revisions\/942"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}