BRADERY Posted August 30, 2010 Share Posted August 30, 2010 Ok I have a file with my emails and passwords like this email:pass email:pass email:pass email:pass and so on.. Is it possible to make a script that will delete everything after the ":" and replace the ":" with a comma? Im not sure what functions or w/e I could use to make this possible? Any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/212043-php-edit-file/ Share on other sites More sharing options...
jcbones Posted August 30, 2010 Share Posted August 30, 2010 So you want to get rid of the passwords in this file. $filename = 'text.txt'; //name of your file. $file = file($filename); //pull the file, and put it in an array. foreach($file as $v) { //loop through the array. list($email,$password) = explode(':',$v); //split each row by the : assigning the variable $email before the colon, and $password after it. $emails[] = $email . ','; //append a comma onto the end of the email, and assign it to the emails array. } file_put_contents($filename,implode("\n",$emails)); //implode the data on a newline and send it back to the file, in OVERWRITE mode. This will do it, although make sure you really want to, or at least make a copy of the original incase you want to reverse it. Quote Link to comment https://forums.phpfreaks.com/topic/212043-php-edit-file/#findComment-1105044 Share on other sites More sharing options...
BRADERY Posted August 30, 2010 Author Share Posted August 30, 2010 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/212043-php-edit-file/#findComment-1105054 Share on other sites More sharing options...
BRADERY Posted August 30, 2010 Author Share Posted August 30, 2010 check your Personal messages jc Quote Link to comment https://forums.phpfreaks.com/topic/212043-php-edit-file/#findComment-1105056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.