Skip to content

Instantly share code, notes, and snippets.

@adityadees
Last active May 9, 2021 19:55
Show Gist options
  • Save adityadees/646de08b1ce210004ac9b8352a90e7ee to your computer and use it in GitHub Desktop.
Save adityadees/646de08b1ce210004ac9b8352a90e7ee to your computer and use it in GitHub Desktop.
MSYQL FUNCITON REMOVE HTML TAGS FROM RECORD AND SELECT WITH LIMIT
SET GLOBAL log_bin_trust_function_creators=1;
DROP FUNCTION IF EXISTS funcStripTags;
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, '');
set Dirty = Replace(Dirty,'&nbsp;','');
set Dirty = Replace(Dirty,'\r','');
set Dirty = Replace(Dirty,'\n','');
END;
END IF;
END;
END WHILE;
RETURN Dirty;
END;
|
DELIMITER ;
SELECT SUBSTRING(funcStripTags(myFieldName), start, end) as myAliasName FROM myTable;
ex :
SELECT SUBSTRING(funcStripTags(news), 1, 150) as news_ss FROM tbl_apps;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment