i am try to create one xml tree. something like this type:-
<products>
<product_id value='1' />
</products>
and i am try to save them into one txt file:-
like 1.txt
<products>
<product_id value='1' />
</products>
in 2.txt
<products>
<product_id value='2' />
</products>
i tried this:-
<?php
// create doctype
$dom = new DOMDocument("1.0");
// display document in browser as plain text
// for readability purposes
header("Content-Type: text/plain");
// create root element
$root = $dom->createElement("products");
$dom->appendChild($root);
for($i=0;$i<2;$i++)
{
//create product_id
$pro_id = $dom->createElement("product_id");
$root -> appendChild($pro_id);
//append attribute ib product_id
$attpro = $dom->createAttribute("value");
$pro_id -> appendChild($attpro);
//append attribue value in product_id
$attval = $dom->createTextNode($i+1);
$attpro -> appendChild($attval);
$a = $i+1;
file_put_contents("$a.txt",$dom->saveXML());
}
echo $dom->saveXML();
?>
its return me output like:-
in 1.txt
<products>
<product_id value='1' />
</products>
in 2.txt
<products>
<product_id value='1' />
</products>
<products>
<product_id value='2' />
</products>
what i want to change for getting all product_id in diff file...
thanks...