I have a function that I use to break large text files into smaller files, and it works great, except that for some reason I can't have any PHP code directly after the function.
Basically I am really confused right now as to what could be causing this.
Here is my function
Calling that function on it's own works perfectly fine when I do it like thisPHP Code:function FileBreakByLine($FileRead, $FileWriteName, $LineCount){
if(substr($FileRead, -2) == "gz"){
$FileOpen = fopen($FileRead, "rb");
fseek($FileOpen, -4, SEEK_END);
$buf = fread($FileOpen, 4);
$GZFileSize = end(unpack("V", $buf));
fclose($FileOpen);
$HandleRead = gzopen($FileRead, "rb");
$ContentRead = gzread($HandleRead, $GZFileSize);
}
else{
$HandleRead = fopen($FileRead, "rb");
$ContentRead = fread($HandleRead, filesize($FileRead));
}
$Lines = explode("\n", $ContentRead);
$TotalGroups = (intval(count($Lines) / $LineCount) + 2);
Echo "Total Lines: ". count($Lines) ."<br>";
Echo "Total Groups: ". $TotalGroups ."<br>";
for($q = 0; $q < $TotalGroups; $q++){
for($x = ($q * $LineCount); $x < (($q * $LineCount) + $LineCount); $x++){
$Text[] = $Lines[$x];
if($x == count($Lines)){
$ScriptComplete = 1;
break;
}
}
$FileText = implode("\n", $Text);
$FileWrite = $FileWriteName . $q .'.txt';
$HandleWrite = fopen($FileWrite, "w");
$ContentWrite = fwrite($HandleWrite, $FileText);
unset($Text);
if($ScriptComplete == 1){
break;
}
}
if(substr($FileRead, -2) == "gz"){
gzclose($HandleRead);
}
else{
fclose($HandleRead);
}
fclose($HandleWrite);
}
But when I try something like thisPHP Code:require 'Includes/PHPFunctions.php';
FileBreakByLine('data/BigFile.txt', 'Data/Test', '1200')
Nothing comes up on the screen. I turned error reporting on and still just a blank screen.PHP Code:require 'Includes/PHPFunctions.php';
FileBreakByLine('data/BigFile.txt', 'Data/Test', '1200')
echo "Yay";
So I got clever and did this
And it works fine.PHP Code:<?php
require 'Includes/PHPFunctions.php';
FileBreakByLine('data/BigFile.txt', 'Data/Test', '1200')
?>
<?php
echo "Yay";
?>
I know this has to be something simple, but I just don't know what it could be.
Any help?







reminds of a problem I had a few weeks ago. I accidently hit the backtick - ` and it was throwing a parse error several lines down. The darn thing is so small I didn't see it (thought it was dust on the screen) for a good hour.

Bookmarks