12-14-2007, 05:43 PM
|
#7 (permalink)
|
|
The Contributor
Join Date: Oct 2007
Location: Argentina
Posts: 72
Thanks: 18
|
Ok, here is a quick simple solution, im pretty sure there must be a better way to do this but anyways hope it helps you:
On one side theres test.txt (CHMOD this file to 777)
Quote:
|
I added other random stuff just to simulate that there's more data than the one we are updating
|
Code:
define("NAMEOFAPP", "SOME APP");
define("KEYWORDS", "Keyword,Stuff,Etc");
define("DESCRIPT", "This is my description.");
define("SOMETEXT", "Blah Blah Blah");
$szVar = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"
$iSum = 1 + 2;
define("SOMETHING","Another thing");
And then the little script:
PHP Code:
// Define an array with the new values you want to write. $aNewValues = array( "NAMEOFAPP" => "This is the new name of my APP", "KEYWORDS" => "OTHER Keywords,Stuff,Etc", "DESCRIPT" => "This is my NEW description.", "SOMETEXT" => "A NEW Blah Blah Blah", );
$fName = 'test.txt'; $fHandle = fopen($fName,"r"); $szContent = fread($fHandle,filesize($fName));
// Simple foreach with regEX to find/replace the content foreach ($aNewValues as $key => $value) {
$szNew = 'define("'.$key.'", "'.$value.'");'; $szContent = preg_replace("/define\(\"".$key."\"\,\s?\"[A-Z,\s.]*\"\)\;/i",$szNew,$szContent); };
//Save the new content and close $fHandle = fopen($fName,"w"); fwrite($fHandle,$szContent); fclose($fHandle);
Cheers
|
|
|
|