Jump to content

Editing a line in a file


Guardian-Mage

Recommended Posts

Ok, I have a php file, I need to open it, find the line that reads "$pass[0]  = "fa03eb688ad8aa1db593d33dabd89bad";" and edit the value

"fa03eb688ad8aa1db593d33dabd89bad". How can I do that, I have

 

#Open the file

$ourFileName = "access.php";

$fh = fopen($ourFileName, 'r+') or die("Can't open file");

fclose($fh);

Link to comment
https://forums.phpfreaks.com/topic/69515-editing-a-line-in-a-file/
Share on other sites

You could try 'preg_replace()', ref http://uk3.php.net/manual/en/function.preg-replace.php...

say

$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$contents = preg_replace("fa03eb688ad8aa1db593d33dabd89bad", "new_hash", $contents);
// resave file

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.