php replace pass with ***

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bizkit1
Forum Newbie
Posts: 11
Joined: Wed Oct 05, 2011 5:20 am

php replace pass with ***

Post 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!
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: php replace pass with ***

Post 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);
Post Reply