SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2001
    Location
    Kennesaw, GA
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SSI -> PHP conversion

    I've got this website with hundreds of pages using ssi.
    I need to get just the raw content out of them and store them somewhere else on the server.
    The problem is, they are all in different directories...
    I.E. /nav/subject/page/index.shtml
    /nav/subject/page2/index.shtml
    /nav/subject2/page/index.shtml
    /nav/subject2/page2/index.shtml

    etc.
    I know it's a horrible way to do things -- this is why I'm trying to change them. I need to literally write a script to do the job for me because there are so many pages. Hundreds upon hundreds. Wayyy too many for a manual conversion. I don't know anything about switching directories -- obviously it would have to
    1) List directories
    2) Choose the directory
    3) Choose a page
    4) Read the file
    5) Replace everything I didnt want in it with "" or something, deleting everything but the raw content then save it to another directory as the name of the subject plus a page number or something .php
    6) Go back
    7) Go into the next page
    8) Repeat step 5
    9) go all the way back to /nav or whatever and repeat over and over

    The other concern I have is the maximum execution time for PHP
    is this going to be over 30 seconds, etc.

    Solutions... help?
    dsntre

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, this code searches recursively from a given starting point all the directories and subdirectories.. I use it for finding and deleting .bak files that I have forgotton to delete.

    You would have to tweak it but at least it gets over the recursive stuff which is a pain..

    PHP Code:
    <?
    if($input){

    function 
    GetDirArray($sPath,$del) {  global $num_bak$fileval;
    $fileval="bak";//CHANGE THIS TO SHTML OR WHATEVER//
    $handle=opendir($sPath); 

        while (
    $file readdir($handle))
            { 
        
    $retVal[count($retVal)] = $file
            } 

    closedir($handle); sort($retVal); 

    while (list(
    $key$val) = each($retVal)) { 
        if (
    $val != "." && $val != "..") { 
                
    $path str_replace("//","/",$sPath."/".$val);
                

                
    //THIS BIT DODGILY CHECKS IF THERE IS A FILE *.BAK AND DELETES IT//
        
    if(substr($path,-3,3)==$fileval)
                {
    echo 
    $path;

                    if(
    $del){
                                
    //PUT YOUR CODE HERE//
                        
    $path str_replace("//","/",$sPath."/".$val);//unlink($path);
                        //END HERE!//
                    
    }


                    
    $num_bak++;
                    if(
    $sPath!=$oldpath)
                            {
                            echo 
    "<br><b>$sPath</b><br>";
                            
    $oldpath=$sPath;
                            }
                echo 
    "$path <br>"
                }

        if (
    is_dir($sPath."/".$val)) 
                { 
                    
    GetDirArray($sPath."/".$val."/",$del); 
                }
            }
        }
    }  

    GetDirArray($input,$del);
    if(
    $num_bak)
            {
                echo 
    "<h3>Total $num_bak .$fileval files</h3>";
                echo 
    "<a href=\"$PHP_SELF?del=1&input=$input\"><h4>Delete *.$fileval files</h4></a>";
        }else{
                echo 
    "<h4>There are no .$fileval files to delete</h4>";
            }
        echo 
    "<br><a href=\"$PHP_SELF\">back</a>";

    }else{
    //if input//

    ?>
    <form name="bella" method="post" action="<? echo $PHP_SELF;?>">
    Directory to scan for <?=$fileval;?> files:<input type="text" name="input">
    <input type="submit" name="submit" value="go">
    </form>
    <?}?>
    (Note the path to enter directories is relative to $DOCUMENT_ROOT)

    So in the //PUT YOUR CODE HERE BIT// , you should perfom any operations you want on the file (which will be called $path).., this script lists the files that will be affected before actually doing anything & I have commented out the unlink()!!!!

    hope its useful in some way? ,
    PS I scan my whole C:\ drive with this script and have yet to time out, but you can set the timeout value runtime if you run into problems.


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
  •