Page 1 of 1

Using cat command to combine files

Posted: Thu Nov 11, 2010 4:47 pm
by golfrguy7
Hey guys,

I'm brand new to PHP, so I apologize if this is a really stupid question. I'm working on an android application that uses XML that is stored online. The client has a page that uses PHP to write to the XML file. Currently, I have a .xml file that contains all of the data that the program needs, but when I append to it I'm unable to close the root tag. My professor told me to use php to call a unix command (pretty sure the "cat" command) to write the following to a file. "<AllCards>", $cards.xml, "</AllCards>" and then save the file as allcards.xml.

Here is some example input and output of what I want to do.
Input (cards.xml):

Code: Select all

<FlashCard>
 <name> Card Name </name>
 <description> Description goes here </description>
 <chapter> 10 </chapter>
 <picture> URL to Picture </picture>
 <sound> URL to sound </sound>
</FlashCard>
The php currently just appends a new <FlashCard> to cards.xml. He wants us to call the cat command so that it generates allcards.xml as:

Code: Select all

<AllCards>
<FlashCard>
..
</FlashCard>
</AllCards>
Anybody know how to do this? I'd talk to my professor, but he's out of town until Monday. Thanks!!

Re: Using cat command to combine files

Posted: Thu Nov 11, 2010 5:42 pm
by Celauran