php file append

Reply

Join Date: Apr 2009
Posts: 19
Reputation: odysea is an unknown quantity at this point 
Solved Threads: 0
odysea odysea is offline Offline
Newbie Poster

php file append

 
0
  #1
May 9th, 2009
have this script

  1. $idhandle = fopen($filename, 'r+') or die("can't open file");
  2. $id = "<?php \$lastid = \"$lastid\"; ?>";
  3.  
  4. fwrite($idhandle, $id);
  5. fclose($idhandle);

trying to write "<?php \$lastid = \"$lastid\"; ?>"; in the first line of the file but what is happening is its deleting some of my code in the file. any way that you can skip a line or someting to preserve the coding that is already in the filename ?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 222
Reputation: chrishea is an unknown quantity at this point 
Solved Threads: 32
chrishea's Avatar
chrishea chrishea is offline Offline
Posting Whiz in Training

Re: php file append

 
0
  #2
May 9th, 2009
Starting with the obvious, why are you using:
  1. $id = "<?php \$lastid = \"$lastid\"; ?>";

instead of:
  1. $id = $lastid;
Chris
See my list of PHP development tools at:
InnovationsDesign.net
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,516
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

Re: php file append

 
0
  #3
May 11th, 2009
If you are trying to send php code to the file then perhaps it is better to use single quotes like the following so variables inside the string do not display their values:
  1. $idhandle = fopen($filename, 'r+') or die("can't open file");
  2. $id = '<?php $lastid = "$lastid"; ?>';
  3.  
  4. fwrite($idhandle, $id);
  5. fclose($idhandle);
Or if you just want the value of the second variable substituted with its value while the first variable stays as it is:
  1. $id = '<?php $lastid = "'.$lastid.'"; ?>';
Or if you want all of the variable names substituted with their values
  1. $id = "<?php $lastid = \"$lastid\"; ?>";
It is unclear exactly what result you want in the text file but I hope the above examples help solve the question.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - MacGyver Fan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC