--select fnc_slug('Minha URL utilizando a função slug')
CREATE OR REPLACE FUNCTION promocoes.fnc_slug(pTexto varchar) RETURNS varchar AS
$body$
declare
vSlug varchar;
begin
vSlug := pTexto;
/*
vSlug := replace(vSlug , 'æ', 'ae');
vSlug := replace(vSlug , 'œ', 'oe');
vSlug := replace(vSlug , '€', 'euros');
vSlug := replace(vSlug , '$', 'dollars');
vSlug := replace(vSlug , '£', 'pound');
vSlug := replace(vSlug , '¥', 'yen');
vSlug := replace(vSlug, 'U$', 'dolares');
vSlug := replace(vSlug, 'R$', 'reais');
*/
vSlug := regexp_replace(translate(replace(lower(vSlug), ' ', '-'),
'áàâãäå???ÁÂÃÄÅ???èééêë????????É??ìíîïì???ÌÍÎÏÌ???óôõö???ÒÓÔÕÖ???ùúûü????ÙÚÛÜ????çÇÿ&,.ñÑ',
'aaaaaaaaaaaaaaaaaeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiooooooooooooooouuuuuuuuuuuuuuuuccy_--nn'), E'[^\\w -]', '', 'g');
while position('--' in vSlug) > 0 loop
vSlug := replace(vSlug , '--', '-');
end loop;
return vSlug;
end;
$body$
LANGUAGE 'plpgsql'
Nenhum comentário:
Postar um comentário