Page 1 of 1

php replace pass with ***

Posted: Sun Nov 06, 2011 11:03 pm
by bizkit1
Hello. I have a txt file which contains username, password, acces flasgs and immunity flag, something like this

"username" "password" "flagsabcdefgh" "imflag"

I want to display this txt in a page, but without the password. I want to replace the password with *****. Can you please help me with this? Thanks!

Re: php replace pass with ***

Posted: Mon Nov 07, 2011 12:10 am
by twinedev
Well, it depends how you are reading the text file and displaying it, can you give an example of the code how it is displaying now?

If you are just reading it in line by line (where the example you gave would be one line of information in a variable) and that you know for sure that username and password will NOT have a quote in them, then the following regex would probably do:

Code: Select all

$strReplacement = '***';
$strLine = preg_replace('/^("[^"]+" ")([^"]+)(" .*)$/i', '$1'.$strReplacement.'$3', $strLine);