コードの下に発生するすべての10行私のファイルを分割し、私はそれが毎回分割大きなファイル毎回</byebye>は
</byebye>
発生分割したいです。そうすれば、私はそれぞれ複数のファイルを含むでしょう。
<byebye>
*stuff here*
</byebye>
コード:
<?php
/**
*
* Split large files into smaller ones
* @param string $source Source file
* @param string $targetpath Target directory for saving files
* @param int $lines Number of lines to split
* @return void
*/
function split_file($source, $targetpath='files/', $lines=10){
$i=0;
$j=1;
$date = date("m-d-y");
$buffer='';
$handle = @fopen ($source, "r");
while (!feof ($handle)) {
$buffer .= @fgets($handle, 4096);
$i++;
if ($i >= $lines) {
$fname = $targetpath.".part_".$date.$j.".xml";
if (!$fhandle = @fopen($fname, 'w')) {
echo "Cannot open file ($fname)";
exit;
}
if ([email protected]($fhandle, $buffer)) {
echo "Cannot write to file ($fname)";
exit;
}
fclose($fhandle);
$j++;
$buffer='';
$i=0;
$line+=10; // add 10 to $lines after each iteration. Modify this line as required
}
}
fclose ($handle);
}
split_file('testxml.xml')
?>
任意のアイデア?
xmlで使用するsimplexml_load_string()を使用 – Ibu
これまでに何を試みましたか? –
大きなXMLサンプルを投稿する可能性がありますか、BYEBYE要素のそれぞれのコンテンツを個別のXMLファイルに保存することを確認できますか? –