Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I want to convert the XML structure below into a PHP array.

<BillingApplyRq>
    <FatoryId>xxxxxx</FatoryId> 
    <TotalNum>2</TotalNum> 
    <Records> 
        <Record> 
            <ReturnMsgNo>1</ReturnMsgNo> 
            <ReturnMsg></ReturnMsg> 
            <TradeSeq>00001</TradeSeq> 
        </Record> 
        <Record> 
        <ReturnMsgNo>1</ReturnMsgNo> 
        <ReturnMsg></ReturnMsg> 
        <TradeSeq>00002</TradeSeq> 
        </Record> 
    </Records> 
</BillingApplyRq>

Does anyone know how to do that?

share|improve this question
 
General questions about programming is off-topic on Drupal Answers, but can be asked StackOverflow. This one already has an accepted answer there: stackoverflow.com/questions/6578832/… –  Gisle Hannemyr Aug 16 at 7:20
 
thx. i will ask @ stackoverflow in the future. –  cobenash Aug 16 at 8:19

closed as off-topic by Gisle Hannemyr, Clive Aug 16 at 7:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on programming, PHP, SQL, etc. that do not relate directly to Drupal are off-topic here, but can be asked on Stack Overflow." – Gisle Hannemyr, Clive
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 1 down vote accepted

Although this is not related to Drupal but anyway you must convert from XML to array by using the sample code below from PHP.net

$simple = "<para><note>simple note</note></para>";
$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $vals, $index);
xml_parser_free($p);
echo "Index array\n";
print_r($index);
echo "\nVals array\n";
print_r($vals);

Ref: xml_parse_into_struct — Parse XML data into an array structure

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.