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!
php replace pass with ***
Moderator: General Moderators
Re: php replace pass with ***
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:
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);