Censoring parts of a string
#1

Hello, how can i censore parts of a string like from testemail@yahoo.com to tes******@ya***.com
Reply
#2

You can make a loop to go through every char. and replace the ones you want.
Reply
#3

And how i would do that, i tried looping with an for through all characters but i don't know how to replace what i want
Reply
#4

You can do it like this:

PHP код:
stock CensorMail(const mail[])
{
    new 
strfind(mail,"@"), strfind(mail,".",false,c+1), censored[64] = "Fake Mail!";
    if(
== -|| == -|| 3) return censored;
    
format(censored,64,mail);
    for(new 
i=(c==3)?1:3i<ci++) censored[i] = '*';
    for(new 
i=(p-== 4)?c+2:c+3i<pi++) censored[i] = '*';
    return 
censored;
}
//Example:
print(CensorMail("testemail@yahoo.com")); //Output: tes******@ya***.com
print(CensorMail("aaa@web.de")); //Output: a**@w**.de 
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)