简体   繁体   中英

A way to return XML output from a PHP shell_exec?

I need to be able to run the Linux find command from a PHP program, and want to be able to have it return the output of the find as an XML. Is this possible to do? I want to be able to do this so I can easily find the parent (directory) for each child (file). Or is there a better way to do this? Thanks!

You wouldn't get the output from the find command as xml, it will just return text (as it only ever should).

your best bet would probably to create the xml you want from the text that is returned when you use exec to run find.

example sudo code:

get all info you want to find: exec(find);
create barebones xml string;
create xml object ("i'd use simplexml in this example");
simplexml->addchild(info found from exec find);

sorry for only sudo code, couldn't write anything up in my current situtation

Helpful refenece if you don't know about simplexml:

http://us3.php.net/manual/en/book.simplexml.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM