I have this to split a file into smaller files with 200000 characters each.
$i = 1;
$fp = fopen("styles.css",'r');
while(! feof($fp)) {
$contents = fread($fp,200000);
file_put_contents('styles'.$i.'.css',$contents);
$i++;
}
However, splitting a css file requires more than that. I'll need to have each of them in correct css format. For example:
Original css:
.red {
color: red;
font-weight: bold;
font-size: 15px;
background: black;
}
.blue {
color: blue;
}
What might happen:
.red {
color: red;
font-weight: bold;
font-size: 15px;
background: black;
-------------------split--------------------
}
.blue {
color: blue;
}
What I expect
.red {
color: red;
font-weight: bold;
font-size: 15px;
background: black;
}
-------------------split--------------------
.blue {
color: blue;
}
Is there a way to have PHP split file by number of character, but always make sure that every file ends with "}"? So some file has more than 200000 characters, and some file has less than 200000 characters.
This is not a duplicated question since I want to split file and keep all the pieces, not just cutting a string.