SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Skookum's Avatar
    Join Date
    Sep 2006
    Location
    Idaho
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function Confusion

    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
    PHP Code:
    function FileBreakByLine($FileRead$FileWriteName$LineCount){
        if(
    substr($FileRead, -2) == "gz"){
            
    $FileOpen fopen($FileRead"rb");
            
    fseek($FileOpen, -4SEEK_END);
            
    $buf fread($FileOpen4);
            
    $GZFileSize end(unpack("V"$buf));
            
    fclose($FileOpen);
            
    $HandleRead gzopen($FileRead"rb");
            
    $ContentRead gzread($HandleRead$GZFileSize);
        }
        else{
            
    $HandleRead fopen($FileRead"rb");
            
    $ContentRead fread($HandleReadfilesize($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);

    Calling that function on it's own works perfectly fine when I do it like this
    PHP Code:
    require 'Includes/PHPFunctions.php';

    FileBreakByLine('data/BigFile.txt''Data/Test''1200'
    But when I try something like this
    PHP Code:
    require 'Includes/PHPFunctions.php';

    FileBreakByLine('data/BigFile.txt''Data/Test''1200')
    echo 
    "Yay"
    Nothing comes up on the screen. I turned error reporting on and still just a blank screen.

    So I got clever and did this
    PHP Code:
    <?php
    require 'Includes/PHPFunctions.php';

    FileBreakByLine('data/BigFile.txt''Data/Test''1200')
    ?>
    <?php
    echo "Yay";
    ?>
    And it works fine.

    I know this has to be something simple, but I just don't know what it could be.

    Any help?
    Paranoia is no longer a mental illness it is a way of life - Me

  2. #2
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And what about this?

    PHP Code:
    <?
    require 'Includes/PHPFunctions.php'

    FileBreakByLine('data/BigFile.txt''Data/Test''1200'); 
    echo 
    "Yay"

    ?>
    You are missing the ; at the end of your function. Result, php is taking that as a single line, like you are calling a function like

    PHP Code:
    FileBreakByLine('data/BigFile.txt''Data/Test''1200')echo "Yay"
    which was not making any sense ...

  3. #3
    SitePoint Addict Skookum's Avatar
    Join Date
    Sep 2006
    Location
    Idaho
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    Wow, I need a break.

    Thanks for pointing that out it works perfectly now. I knew it was something simple, I just didn't want it to be something that simple.

    Thanks for the help.
    Paranoia is no longer a mental illness it is a way of life - Me

  4. #4
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah ... that day I wasted more than 5 hours because I was missing a space. I was having a list seperated by a comma and a space, and then I was exploding with only a comma.

    Happens sometime ...

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    parse errors

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •