Questions
strip_tags in mysql
PHP Strip_tags in Mysql :-
use the strip_tags() function to strip the html tags in SQL,Syntax
:-
SELECT * FROM pages WHERE strip_tags(body) LIKE '%keywords%';
MYSQL function :-
CREATE FUNCTION strip_tags( x longtext) RETURNS longtext
LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA
BEGIN
DECLARE sstart INT UNSIGNED;
DECLARE ends INT UNSIGNED;
SET sstart = LOCATE('<', x, 1);
REPEAT
SET ends = LOCATE('>', x, sstart);
SET x = CONCAT(SUBSTRING( x, 1 ,sstart -1) ,SUBSTRING(x, ends +1 )) ;
SET sstart = LOCATE('<', x, 1);
UNTIL sstart < 1 END REPEAT;
return x;
END;
Your Answers
Answers
Oct 17 12 07:30:32 |
Substring is used for “Read”, not for “Write”. Say SUM_DMO is '3456 , you want to change it to '1156 , you can do like this: (this is mySQL stynax, if you use SQL Server or Oracle or others, the stynax may be different)UPDATE tableSET SUB_DMO = CONCAT('11 , SUBSTRING(SUM_DMO,3))WHERE field 1 = ’000001688085′ ANDfield2 = ‘TNT’ ANDfield3 =’MTSILV08′ |
Mar 12 12 10:10:50 |
CREATE FUNCTION strip_tags( x longtext) RETURNS longtext LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA BEGIN DECLARE sstart INT UNSIGNED; DECLARE ends INT UNSIGNED; SET sstart = LOCATE('<', x, 1); REPEAT SET ends = LOCATE('>', x, sstart); SET x = CONCAT(SUBSTRING( x, 1 ,sstart -1) ,SUBSTRING(x, ends +1 )) ; SET sstart = LOCATE('<', x, 1); UNTIL sstart < 1 END REPEAT; return x; END; |