Jump to content

PHP edit file?


BRADERY

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.