I have a controller merchant_import and creating an array from xml
public function merchant_import_kgb(){
if (!$this->session->userdata('logged_in')){
redirect('admin/login');
}
$data['pageTitle'] = 'Merchant Admin';
$data['error_warning'] = '';
$data['success'] = '';
$xmlfile= base_url().'feeds/kgb.xml';
$xmlRaw = file_get_contents($xmlfile);
$this->load->library('xml');
$xmlData = $this->xml->xml_parse($xmlRaw);
?><pre><?php var_dump($xmlData); ?></pre><?php
foreach($xmlData['merchant']['prod'] as $product){
list($titleNew, $partner, $city) = explode(" - ", $product['text']['name']);
$deal[] = array(
'id' => $product['pId'],
'dealTitle' => $titleNew,
'price' => $product['price']['buynow'],
'image' => $product['uri']['mThumb'],
'buyLink' => $product['uri']['awTrack'],
'endDate' => $product['valTo'],
'partner' => $partner,
'city' => $city,
'description' => $product['text']['desc'],
'RRP' => $product['price']['rrp'],
'category' => $product['cat']['mCat'],
'discount' => $this->getDiscount($product['price']['buynow'], $product['price']['rrp'])
);
}
?><pre><?php var_dump($deal);?></pre><?php
}
The problem I am having is that the $parts[2] is giving an undefined offset with some and others its formating nicely. I have checked the xml and all titles are Title - Partner - City - kgbdeals. When formatting array though the explode() isn't working correctly. Any ideas?
Edit - tried using preg_split(), split(), and explode all with near enough same result, totally lost :(
Thanks Joe