Remove HTML tags using mysql

mysql

This is just a reminder to a great sql code I needed these days.



SET GLOBAL logbintrustfunctioncreators=1;
DROP FUNCTION IF EXISTS fnRemoveHtml;
DELIMITER |
CREATE FUNCTION fnRemoveHtml( Dirty varchar(4000) )
RETURNS varchar(4000)
DETERMINISTIC 
BEGIN
  DECLARE iStart, iEnd, iLength int;
    WHILE Locate( '<', Dirty ) > 0 And Locate( '>', Dirty, Locate( '<', Dirty )) > 0 DO
      BEGIN
        SET iStart = Locate( '<', Dirty ), iEnd = Locate( '>', Dirty, Locate('<', Dirty ));
        SET iLength = ( iEnd - iStart) + 1;
        IF iLength > 0 THEN
          BEGIN
            SET Dirty = Insert( Dirty, iStart, iLength, '');
          END;
        END IF;
      END;
    END WHILE;
    RETURN Dirty;
END;
|
DELIMITER ;

Link: forums.mysql.com


We request your permission to obtain statistical data on its navigation on this website. If you continue to browse we consider to accept the use of cookies. OK | More Information