SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: AutoTab...

  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AutoTab...

    Hi,

    Recently, Padders posted a thread about autotab script that he'd made. If you look at it, you'll find i became interested and tried to fix one of the bugs which is that if someone has :

    PHP Code:
    if($blah)
    { echo 
    $i; } 
    ..the autotab doesn't work. Therefore, I came up with this:

    PHP Code:
    <?php

    $dir 
    opendir(".");
    while (
    $file readdir($dir)) {
        if (
    strstr($file".php")) {
            
    $fcontents file($file);
            while (list (
    $line_num$line) = each ($fcontents)) {
            if (
    strstr($line"}")) {
                
    $tab--;
            }

    if (!((
    strstr($line"\\")) OR (strstr($line"####")))) {

                
    $new_file .= growstring("\t"$tab);



      }
    $a substr($line,0,1);
    $b substr($line,-1);


    if((
    $a == "{") && ($b == "}")) {
        
    $new_files .= substr_replace($line"{\n"01);
    $new_file .= substr_replace($new_files"\n}", -1);
    }

       echo 
    $line;


            
    $new_file .= trim($line) . "\n";
            if (
    strstr($line"{")) {
                
    $tab++;

            }
        }
        
    $file2 fopen($file"w");
        
    fputs($file2$new_file);
        unset(
    $new_file);
        unset(
    $tab);
    }
    }
    function 
    growstring($string$number) {
    for (
    $idx 0$idx $number; ++$idx) {
        
    $newstring .= $string;
    }
    return 
    $newstring;
    }

    ?>
    This code works, if I do not use a file, but just a variable. In this version nothing happens at all. Any clues?

    -Peter

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think i got it workng:

    PHP Code:
    <?php

    $dir 
    opendir(".");
    while (
    $file readdir($dir)) {
        if (
    strstr($file".php")) {
            
    $fcontents file($file);
            while (list (
    $line_num$line) = each ($fcontents)) {
                
                
                
            if (
    strstr($line"}")) {
                
    $tab--;
            }
            
            
    if (!((
    strstr($line"\\")) OR (strstr($line"####")))) {
    $new_file .= growstring("\t"$tab);
                
                
            }
            
    $a substr($line,0,1);
            
    $b substr($line,-3);
            
    $c substr($line,-2);
            
    if((
    $a == "{") AND (($b == "}\r\n") OR ($c == "}\n"))) {
    if(
    $b == "}\r\n") {
            
    $d = -3;
        } else {
            
    $d = -2;
        }
        
    $new_lines substr_replace($line"{\n"01);
    $new_lines substr_replace($new_lines"\n}\n"$d,-1);
        echo 
    $new_lines;
        
    $new_file .= trim($new_lines);
        
        unset(
    $new_lines);
    }  else {
    $new_file .= trim($line) . "\n";
    }
    if (
    strstr($line"{")) {
        
    $tab++;
        
    }

    }
    $file2 fopen($file"w");
    fputs($file2$new_file);
    unset(
    $new_file);
    unset(
    $tab);
    }
    }

    function 
    growstring($string$number) {
    for (
    $idx 0$idx $number; ++$idx) {
    $newstring .= $string;
    }
    return 
    $newstring;
    }

    ?>


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
  •