Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6528873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:34:32+00:00 2026-05-25T09:34:32+00:00

I’m close to finishing a script which uses simplexml to process some data but

  • 0

I’m close to finishing a script which uses simplexml to process some data but I am stuck at the last.

Well, not stuck, but curious and stuck.

$tmp contains my XML (approx 750k) and the goal is to get it into a format for fputcsv (a parent array containing an array for each row).

The below works, but instead of a nice clean array that I can use fputcsv and send back to user there is a lot of overhead which I do not need for writing to a CSV file and which will create me problems no doubt with fputcsv. I have cleaned the output up into just a couple of header columns and just a couple of rows, but in reality there are 20 columns and hundreds of rows. Anyway to clean before fputcsv?

        // Process XML response into arrays for fputcsv
        $csv = array();
        $xml = simplexml_load_string($tmp);

        // Create array and loop each column for header row
        $header_row = array();
        foreach ($xml->RESPONSE->DATA->HEADER->COLUMN as $column) {
            $header_row[] = $column;
        }
        $csv[] = $header_row;

        // Create array and loop each column for header row

        foreach ($xml->RESPONSE->DATA->ROW as $row) {
            $data_row = array();
            foreach ($row->COLUMN as $datacolvalue){
                $data_row[] = $datacolvalue;
            }
            $csv[] = $data_row;
            unset($data_row);
        }

        // Output var to check for accuracy (later add fputcsv)
        var_dump($csv);

Output (print_r – can var_dump if required):

Array
(
    [0] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [0] => date
                )

            [1] => SimpleXMLElement Object
                (
                    [0] => name
                )
)

    [1] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [data_type] => text
                        )

                    [0] => Aug 01, 2011
                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [data_type] => text
                            [id] => 8699636
                        )

                    [0] => bfxgbfgxbfbgxfsfsdf
                )

        )

        [2] => Array

        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [data_type] => text
                        )

                    [0] => Aug 01, 2011
                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [data_type] => text
                            [id] => 8699694
                        )

                    [0] => bfxgbfgxbfbgxf
                )

        )
)

Desired output (extrapolated for each additional column and removing @attributes):

array(
array("date","name"),
array("Aug 01, 2011","bfxgbfgxbfbgxfsfsdf"),
array("Aug 01, 2011","bfxgbfgxbfbgxf")
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:34:33+00:00Added an answer on May 25, 2026 at 9:34 am

    Answering my own question, because I probably didn’t explain it well enough, but specifying a (string) got me to where I needed to be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I want to construct a data frame in an Rcpp function, but when I
I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.