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 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. 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! 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 Link to comment https://forums.phpfreaks.com/topic/212043-php-edit-file/#findComment-1105056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.