I'm chopping up a long SQL file into two files using php to do so (as I don't want to sit here all day selecting text). I'm doing this with the following:
The input .sql file is looped though and written to a file line by line until it reaches the text in the $compareline variable, upon which it stops writing to the file and starts writing to a new file. Or at least it does in theory. The problem is with the string comparison. The contents of $compareline are exactly those of one of the lines of the .sql file imported. Why, then, does the string comparison not equal 0 when this line is looped through, thereby starting a new file output? Am I wording something wrong here? Any ideas would be greatly appreciated.PHP Code:$file_no = 1;
$input = file('dbfile.sql');
$output = fopen('output' . $file_no . '.sql', 'w');
$compareline = "# Table structure for table `products_description`";
foreach($input as $line) {
if(strcasecmp($line, $compareline) == 0) {
fclose($output);
$file_no++;
$output = fopen('output' . $file_no . '.sql', 'w');
} else {
fwrite($output, $line);
}
}
Thanks,
TWR





Bookmarks