MySQL Forums :: PHP :: Removing HTML tags using mysql


Advanced Search

Re: Removing HTML tags using mysql
Posted by: Peter Brawley ()
Date: October 16, 2007 10:39AM

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
  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 ;
SELECT fnStripTags('this <html>is <b>a test</b>, nothing more</html>');

Options: ReplyQuote


Subject Written By Posted
Removing HTML tags using mysql amit sankhala 10/12/2007 05:15AM
Re: Removing HTML tags using mysql Hartmut Holzgraefe 10/15/2007 11:08AM
Re: Removing HTML tags using mysql amit sankhala 10/15/2007 11:27PM
Re: Removing HTML tags using mysql amit sankhala 10/19/2007 02:47AM
Re: Removing HTML tags using mysql Diego Medina 10/19/2007 10:21PM
Re: Removing HTML tags using mysql amit sankhala 10/20/2007 12:19AM
Re: Removing HTML tags using mysql ronnie pack 01/22/2009 02:57AM
Re: Removing HTML tags using mysql Peter Brawley 10/15/2007 03:07PM
Re: Removing HTML tags using mysql amit sankhala 10/15/2007 11:22PM
Re: Removing HTML tags using mysql Peter Brawley 10/16/2007 10:39AM
Re: Removing HTML tags using mysql amit sankhala 10/17/2007 04:22AM
Re: Removing HTML tags using mysql k7 m 06/06/2008 12:11AM
Re: Removing HTML tags using mysql Peter Brawley 06/06/2008 11:02AM
Re: Removing HTML tags using mysql qammar feroz 04/01/2009 08:03AM
Re: Removing HTML tags using mysql qammar feroz 04/09/2009 04:45AM
Re: Removing HTML tags using mysql Ranjita 01/20/2009 07:38AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.