PDA

View Full Version : modifying files content via php


Acers
06-08-2006, 05:56 PM
I am trying to build something for which i would need to modify a files content via another file.

eg i have say 2 files file1.php and file2.php

i want to modify the content of file2.php(in that just one line i have to modify. supposing it reads

$varid={some name};

Now there is some other code in file2.php also which is static.


what i want to do is to execute file1.php and from a variable thats generated there (i get value of {some name} from file 1, i update the file2.php.

possible? i read that creating a new file2.php might do this also.


<?php
$fn = "file2.php";
$file = fopen($fn, "w+");
$size = filesize($fn);
$filecontents=(full contents of file with {Some name} added
if($somecondition) fwrite($file, $filecontents);
fclose($file);
?>

could there be a search replace kinda function or the above way is only way?

calorie
06-21-2006, 07:51 PM
An idea via pseudocode...

if some condition from file one

read file two into string

do regexp string replace

write file two to a file

end if

Acers
06-23-2006, 08:39 AM
hi calorie.. thanks.. i had completely forgotten about this thread :)
yep i had gt it working with str_replace that day only
thanks btw :)