Using cat command to combine files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
golfrguy7
Forum Newbie
Posts: 1
Joined: Thu Nov 11, 2010 4:38 pm

Using cat command to combine files

Post 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!!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Using cat command to combine files

Post by Celauran »

Post Reply