0

I'm working on storing result of xml feed into database... I'm able to load file... but when I want to store data into array, it stores instead of value ([title] = 'Klapka 120mm';) this:

[title] => SimpleXMLElement Object ( [0] => Klapka 120mm )

Do you know, where might be problem?

Source code:

Here is part of one function:

$import_file = simplexml_load_file($this->input->post('import_url')); // load file from url
$affected_products = 0;
     foreach($import_file->SHOPITEM as $product) {
                    $affected_products += $this->import_product($product);
    }   

Here is first part of function import_product:

public function import_product($product) 
{   
    /* save product data into array */
   $data = array(
            'title' => $product->PRODUCT,
            'content' => $product->DESCRIPTION,
            'price' => $product->PRICE,
            'price_vat' => $product->PRICE_VAT,
            'ean' => $product->EAN,
            'count' => $product->AVAILABILITY
        );
   die(print_r($data));

Thank you very much for your replies

1
  • $data = array_map('strval', $data); Commented Oct 11, 2014 at 20:11

1 Answer 1

0

You have to cast the elements to strings, as all these elements are instances of SimpleXMLElement.

$data = array(
  'title'     => (string)$product->PRODUCT,
  'content'   => (string)$product->DESCRIPTION,
  'price'     => (string)$product->PRICE,
  'price_vat' => (string)$product->PRICE_VAT,
  'ean'       => (string)$product->EAN,
  'count'     => (string)$product->AVAILABILITY
);

For some of them a cast to an integer or a float may be of interest

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.