Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the value of variables in a Text File

Status
Not open for further replies.

tnsbuff

Technical User
Jan 23, 2002
216
US
Is it possible to create a text file with a bunch of variables that would be used as an include file in a page, but be able to use a separate form to change the values of those variables? In other words, update the values of the variables like you would update a field in a database?

Sorry if this is a silly question, but I'm very new. Maybe someone can point me in the right direction.

Thanks,
 
heres a very similar thing I wrote to add or remove email addresses to a text file for a mailing list, instead of deleteing tho, you want to do e preg_replace or whatever.

hope it points you in the right direction.

<?php
$email=stripslashes($HTTP_GET_VARS['email']);
$mailfile='mailing.txt';
$mailsize=filesize($mailfile);
if(!isset($unsub)){

$fd = fopen($mailfile, &quot;r&quot;) or die ('unable to open file');
$fcontents = file($mailfile);
$newmail=stripslashes(trim($email));

while(list($line_num,$line) = each ($fcontents)){
$line=trim($line);
if(preg_match(&quot;/\b$line\b/&quot;,$newmail)){
echo &quot;$email is already listed<br>&quot;;
print(&quot;<a href='index.htm'> Back to form !</a>&quot;);
exit;
$count=1;
}
}

if($count == 0){
$fd = fopen($mailfile, &quot;a&quot;);
$item=$email.&quot;\n&quot;;
fwrite($fd, $item);
fclose($fd);
echo &quot;added $email to mailing list<br>&quot;;
print(&quot;<a href='index.htm'> Back to form !</a>&quot;);

}
}else{
$backup=&quot;$mailfile.bak&quot;;
$fp = fopen($backup, &quot;w&quot;) or die ('unable to open file');
$fcontents = file($mailfile);
$newmail=trim($email);
while(list($line_num,$line) = each ($fcontents)){
$line=trim($line);
if(!preg_match(&quot;/\b$line\b/&quot;,$newmail)){
fwrite($fp, $line.&quot;\n&quot;);
}else{
echo &quot;Found and removed $newmail from the list&quot;;

}
}
fclose($fp);
copy($backup,$mailfile);
unlink($backup);
}
?> ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks a bunch KarveR! I'll give it a go and see where it leads me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top