我有一個控制器merchant_import和從XML創建陣列笨XML陣列爆炸PHP
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
}
我遇到的問題是,$份[2]是給未定義的一些和其他人其格式化偏移很好。我檢查了xml,所有標題都是Title - Partner - City - kgbdeals。雖然explode()格式化數組時不能正常工作。有任何想法嗎?
編輯 - 嘗試使用使preg_split(),斯普利特(),並與近得相同的結果突然爆炸,完全失去了:(
感謝 喬
所以這將在foreach之上的foreach數組,然後交易數組dealtitle => $標題新? –
剛剛嘗試看到上面的修改後的代碼,仍然給一些交易中的未定義偏移量:(大聲笑 –
拆分(「[ - ]」)我嘗試過空格,也沒有 –