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, "<FIELDS><name>".$_POST["name"]."</name><contact_no>".$_POST["contact_no"]."</contact_no><email>".$_POST["email"]."</email><address>".$_POST["address"]."</address></FIELDS>");
}
fclose($file);
?>
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