data.txt
ha15rs,250,home2.gif,2
ha36gs,150,home3.gif,1
ha27se,300,home4.gif,4
ha4678,200,home5.gif,5
i want convert this textfile into xml using simplexml module using php? thanks :))
p.s. im new to this
EDIT:
<allproperty>
<aproperty>
<postcode></postcode>
<price></price>
<imagefilename></imagefilename>
<visits></visits>
</aproperty>
<aproperty>
<postcode></postcode>
<price></price>
<imagefilename></imagefilename>
<visits></visits>
</aproperty>
<aproperty>
<postcode></postcode>
<price></price>
<imagefilename></imagefilename>
<visits></visits>
</aproperty>
</allproperty>
Although I think XMLWriter is best suited for that task (like in my other answer), if you really want to do it with SimpleXML, here's how:
You will notice that the output is not as clean: it's because SimpleXML doesn't allow you to automatically indent tags.
I will suggest you to use XMLWriter instead, because it is best suited for that (and it's also built-in like SimpleXML):
Of course, you can change the
php://output
argument to a filename if you want it to output to a file.