Want to execute code once in php - Please reply soon

Hi all,

I want to execute a code once in my php program.
Please tell me how to do that.

Please see this line in my program-----------

Code:
if(!strstr(fgets($file_op),“</root>”)) {
fwrite($file,“</root>”);
}
I am trying to add </root> at the end of the statement but it is added as many times as it append the code
see this>
$file = fopen($xmlfile,“a”);

My program is as:

Code:
<?php
$xmlfile = “filename.xml”;
$file_op = fopen(“filename.xml”,“r”);
$file = fopen($xmlfile,“a”);
if(!strstr(fgets($file_op),“<?xml version=‘1.0’?>”))
{
fwrite($file, “<?xml version=‘1.0’?><root>”);
fwrite($file, “<FIELDS><name>”.$_POST[“name”].“</name><contact_no>”.$_POST[“contact_no”].“</contact_no><email>”.$_POST[“email”].“</email><address>”.$_POST[“address”].“</address></FIELDS>”);
}
if(!strstr(fgets($file_op),“</root>”)) {
fwrite($file,“</root>”);
}

else {
fwrite($file, "&lt;FIELDS&gt;&lt;name&gt;".$_POST["name"]."&lt;/name&gt;&lt;contact_no&gt;".$_POST["contact_no"]."&lt;/contact_no&gt;&lt;email&gt;".$_POST["email"]."&lt;/email&gt;&lt;address&gt;".$_POST["address"]."&lt;/address&gt;&lt;/FIELDS&gt;");
}
fclose($file);
?&gt;

it write the </root> statement again and again when I try to append the text in my program.

Please reply soon.

Thanking you.

Harish Pathak