로 변환> 오프셋 정의 그러나 문제는 필자 자신이 CSV 파일을 만들 수 없다는 것입니다. 그것은 상점에서입니다. 그래서, 그것을 수정할 수 없습니다 ... 누군가가이 오류를 해결할 수있는 방법을 알고 있습니까? 여기CSV는 내가이 CSV 파일을 XML
내 코드 : 여기
function csvToXML($inputFilename, $outputFilename, $delimiter = ','){
// Open csv to read
$inputFile = fopen($inputFilename, 'rt');
// Get the headers of the file
$headers = fgetcsv($inputFile, 0, $delimiter);
// Create a new dom document with pretty formatting
$doc = new DOMDocument('1.0', 'utf-8');
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
// Add a root node to the document
$root = $doc->createElement('products');
$root = $doc->appendChild($root);
while (($row = fgetcsv($inputFile, 0, $delimiter)) !== false) {
$container = $doc->createElement('product');
foreach ($headers as $i => $header) {
$child = $doc->createElement($header);
$child = $container->appendChild($child);
$value = $doc->createTextNode($row[$i]);
$value = $child->appendChild($value);
}
$root->appendChild($container);
}
$strxml = $doc->saveXML();
$handle = fopen($outputFilename, 'w');
fwrite($handle, $strxml);
fclose($handle);
}
입력 파일에 쉼표가 구분 기호로 사용되는 것이 아니라 데이터 필드 내에 있습니까? [fgetcsv] (http://php.net/manual/en/function.fgetcsv.php) 호출에 인클로저 유형을 추가해야 할 수도 있습니다. –