> Date: Sun, 27 Jun 2010 12:01:50 -0400
> To: aj...@alumni.iu.edu; php-general@lists.php.net
> From: tedd.sperl...@gmail.com
> Subject: Re: [PHP] Modifying Existing Text File From PHP Is Not Working
> 
> At 7:20 AM -0400 6/27/10, Alice Wei wrote:
> >Hi,
> >
> >I have the code as in the following:
> >
> ><?php
> >
> >$name= "Test";
> >$phone= "123-456-7890";
> >$email = "myem...@mymail.com";
> >$comments = "Test Only";
> >
> >$string = "<message>\n<name>" . $name . "</name>\n<phone>" . $phone 
> >. "</phone>\n<email>".
> >           $email . "</email>\n<comments>" .  $comments . 
> >"</comments>\n</message>";
> >
> >//If file exists. append, otherwise create
> >$file = "messages.xml";
> >$fh = fopen($file,"a");
> >$lines = file($file);
> >
> >//Output a line of the file until the end is reached
> >foreach($lines as $line) {
> >
> >    if (trim($line) == "<messages>") {
> >
> >     $line = "<messages>" . $string; // If string, change it.
> >     echo $line . "<br>";
> >     fwrite($fh, $line);
> >   
> >    }
> >    else {
> >   
> >     // If not don't write anything
> >    echo $line . "<br>";
> >
> >    }
> >   fclose($file); // Close the file.
> >   }
> >?>
> >
> >For some reason, it is writing out the lines, but it is not 
> >f-writing to the file. Here is the file that is meant to be edited:
> >
> ><messages>
> ><message>
> ><name>Me</name>
> ><phone>123-456-7890</phone>
> ><email>t...@test.com</email>
> ><comments>This is my message board!</comments>
> ></message>
> ></messages>
> >
> >Have I missed something here? How come the file cannot perform fwrite 
> >actions?
> >
> >Thanks for your help.
> 
> Do you have permission to write to the file?
> 
> Check the permissions of the file.
> 
> Cheers,
> 
> tedd
> 

I believe I do, since I set my folder permission of this script with modify, 
read, execute and delete. I don't see any errors regarding this either. I have 
changed my code to having the curly brace before I close the file handler, if 
that helps any. Yet, it is still not modifying the file. Have I missed 
something else here?

Thanks for your help.

Alice
> -- 
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
                                          
_________________________________________________________________
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3

Reply via email to