SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
-
Mar 31, 2005, 00:07 #1
String comparison to line of read file
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:
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
-
Mar 31, 2005, 01:36 #2
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Your input line may have a newline on the end, so try:
PHP Code:foreach($input as $line) {
$line = trim($line);
//rest of code here....
Bookmarks