Parser automatiquement les URLs
Voici un bout de code ActionScript qui vous permettra de parser automatiquement les URLs :
votre_texte="texte d'exemple : allez voir le site www.creation3d.org";
// votre_texte est votre texte entrant
lien_trouve=0;
fin=0;
lienaremplacer="";
longueur=votre_texte.length;
for (i=0;i<=longueur;i++) {
jj=votre_texte.substr(i,1);
jj2=votre_texte.substr(i+1,1);
jj3=votre_texte.substr(i+2,1);
jj4=votre_texte.substr(i+3,1);
jj5=votre_texte.substr(i+4,1);
jj6=votre_texte.substr(i+5,1);
jj7=votre_texte.substr(i+6,1);
if (((jj=="h") and (jj2=="t") and (jj3=="t") and (jj4=="p") and (jj5==":") and (jj6=="/") and (jj7=="/") and (lien_trouve==0))or((jj=="H") and (jj2=="T") and (jj3=="T") and (jj4=="P") and (jj5==":") and (jj6=="/") and (jj7=="/") and (lien_trouve==0))) {
harajouter=0;
lien_trouve=1;
nbpoints=0;
longueuraremplacer=0;
debutaremplacer=i;
}
if (((jj=="W") and (jj2=="W") and (jj3=="W") and (lien_trouve==0))or((jj=="w") and (jj2=="w") and (jj3=="w") and (lien_trouve==0))) {
harajouter=1;
lien_trouve=1;
nbpoints=0;
longueuraremplacer=0;
debutaremplacer=i;
}
if (lien_trouve==1) {
if (jj==".") {nbpoints++;}
if ((jj==" ") or (jj=="\\") or (jj=="\n") or (jj=="\r") or (nbpoints>3) or (i==longueur)) {
lien_trouve=0;
finaremplacer=i;
fin=1;
} else {
longueuraremplacer++;
lienaremplacer=lienaremplacer add jj;
}
}
if (fin==1) {
fin=0;
if (harajouter==0) {
votre_texte2=votre_texte.substr(0,debutaremplacer)+"<u><a href=\""+lienaremplacer"\" target=\"_blank\">"+lienaremplacer+"</a></u>"+votre_texte.substring(finaremplacer,longueur);
votre_texte=votre_texte2;
nvellelongueur=lienaremplacer.length+38;
}
if (harajouter==1) {
votre_texte2=votre_texte.substr(0,debutaremplacer)+"<u><a href=\"http://"+lienaremplacer+"\" target=\"_blank\">"+lienaremplacer+"</a></u>"+votre_texte.substring(finaremplacer,longueur);
votre_texte=votre_texte2;
nvellelongueur=lienaremplacer.length+45;
}
i=finaremplacer+nvellelongueur;
longueur=longueur+nvellelongueur;
lienaremplacer="";
}
}
// fin de la routine
trace(votre_texte);