Decoding HTML Entities in MySQL
HTML entities are special characters that are used to represent various symbols and characters in HTML. For example, the character " represents a quotation mark, and < represents a less-than sign.
If you have text data that contains HTML entities, you may want to decode them so that the text is displayed correctly. MySQL does not have a built-in function to decode HTML entities, but you can create a user-defined function (UDF) to do this.
Here is an example of a UDF that you can use to decode HTML entities:
CREATE FUNCTION HTML_UnEncode(X VARCHAR(255)) RETURNS VARCHAR(255) CHARSET latin1 DETERMINISTIC BEGIN DECLARE TextString VARCHAR(255) ; SET TextString = X ; #quotation mark IF INSTR( X , '"' ) THEN SET TextString = REPLACE(TextString, '"','"') ; END IF ; #apostrophe IF INSTR( X , ''' ) THEN SET TextString = REPLACE(TextString, ''','"') ; END IF ; #ampersand IF INSTR( X , '&' ) THEN SET TextString = REPLACE(TextString, '&','&') ; END IF ; #less-than IF INSTR( X , '<' ) THEN SET TextString = REPLACE(TextString, '<','<') ; END IF ; #greater-than IF INSTR( X , '>' ) THEN SET TextString = REPLACE(TextString, '>','>') ; END IF ; #non-breaking space IF INSTR( X , ' ' ) THEN SET TextString = REPLACE(TextString, ' ',' ') ; END IF ; #inverted exclamation mark IF INSTR( X , '¡' ) THEN SET TextString = REPLACE(TextString, '¡','¡') ; END IF ; #cent IF INSTR( X , '¢' ) THEN SET TextString = REPLACE(TextString, '¢','¢') ; END IF ; #pound IF INSTR( X , '£' ) THEN SET TextString = REPLACE(TextString, '£','£') ; END IF ; #currency IF INSTR( X , '¤' ) THEN SET TextString = REPLACE(TextString, '¤','¤') ; END IF ; #yen IF INSTR( X , '¥' ) THEN SET TextString = REPLACE(TextString, '¥','¥') ; END IF ; #broken vertical bar IF INSTR( X , '¦' ) THEN SET TextString = REPLACE(TextString, '¦','¦') ; END IF ; #section IF INSTR( X , '§' ) THEN SET TextString = REPLACE(TextString, '§','§') ; END IF ; #spacing diaeresis IF INSTR( X , '¨' )The above is the detailed content of How to Decode HTML Entities in MySQL?. For more information, please follow other related articles on the PHP Chinese website!