foreach($new_files as $new_file) {
//create file
$myfile = fopen($filename, "w");
//put contents in the file
fwrite($filename, $new_file['content']);
//close the file
fclose($myfile);
}
<?php // demo/temp_jasmine_4.php
/**
* https://www.experts-exchange.com/questions/28967752/Create-multiple-files-from-one-files.html
*/
error_reporting(E_ALL);
echo '<pre>';
$data = Array
( 0 => [
'name' => '3650.5010.16231a_4'
, 'content' => 'IS*00* *00*
gfhfidfioghio
dfgjkhguidf
kfjghjdgfuighuigt
489764896hj
gfhfidfioghio
dfgjkhguidf
kfjghjdgfuighuigt
489764896hj' ]
, 1 => [
'name' => '3650.5010.16231a_5'
, 'content' => 'IA5765897
dghertughfh
457885639057
764769487634
457659639486
fhfidhfh
dghertughfh
457885639057
764769487634
457659639486
fhfidhfh' ]
)
;
// DOES IT LOOK RIGHT? YES
var_export($data);
echo PHP_EOL;
// THE DIRECTORY TO HOLD THE FILES
$dir = 'storage';
// WRITE ONE FILE FOR EACH INTERNAL ARRAY
foreach ($data as $thing)
{
$path = $dir . DIRECTORY_SEPARATOR . $thing['name'];
file_put_contents($path, $thing['content']);
}
// SHOW LINKS SO WE CAN VERIFY THE CONTENT OF THE FILES
foreach ($data as $thing)
{
$path = $dir . DIRECTORY_SEPARATOR . $thing['name'];
$link = '<a target="_blank" href="' . $path . '">' . $thing['name'] . '</a>' . PHP_EOL;
echo $link;
}
In general, if you want to split a file in several smaller files you can use file() function to create an array from a file: each line will become an array item; then you can iterate through the array to get content blocks and save them in another file following your specific criteria.