View Single Post
Old 12-14-2007, 06:43 PM   #7 (permalink)
Matt83
The Contributor
Upcoming Programmer 
 
Matt83's Avatar
 
Join Date: Oct 2007
Location: Argentina
Posts: 72
Thanks: 18
Matt83 is on a distinguished road
Default

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
__________________
http://www.mattvarone.com
Matt83 is offline  
Reply With Quote
The Following User Says Thank You to Matt83 For This Useful Post:
webosb (12-14-2007)