Função para fazer URL decode em Mysql

DELIMITER $$

DROP FUNCTION IF EXISTS `_functions`.`url_decode`$$
CREATE DEFINER=`root`@`%` FUNCTION `_functions`.`url_decode`(original_text text) RETURNS text CHARSET latin1
BEGIN
declare new_text text default null;
declare pointer int default 1;

set new_text = replace(original_text,’+',’ ‘);
while (LOCATE(”%”,new_text,pointer) <> 0 )&& (pointer < length(new_text)) do
set pointer = LOCATE(”%”,new_text,pointer);
set new_text = concat(left(new_text,pointer-1), char(conv(mid(new_text,pointer+1,2),16,10)), right(new_text,length(new_text)-(pointer+2)));
set pointer = pointer + 1;
end while;

return new_text;

END;

$$

DELIMITER ;

Repare que ele utiliza um outro banco para guardar as funções.

Por Garret Hill

2 Responses to “Função para fazer URL decode em Mysql”

  1. AlexM Says:

    I found your site on technorati and read a few of your other posts. Keep up the good work. I just added your RSS feed to my Google News Reader. Looking forward to reading more from you down the road!

  2. AlexM Says:

    Your blog is interesting!

    Keep up the good work!

Leave a Reply