SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2001
    Kennesaw, GA
    0 Post(s)
    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

    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?

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Perth Australia
    0 Post(s)
    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:

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

        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);

    echo $path;

                                //PUT YOUR CODE HERE//
                        $path = str_replace("//","/",$sPath."/".$val);//unlink($path);
                        //END HERE!//

                            echo "<br><b>$sPath</b><br>";
                echo "$path <br>"; 

        if (is_dir($sPath."/".$val)) 

                echo "<h3>Total $num_bak .$fileval files</h3>";
                echo "<a href=\"$PHP_SELF?del=1&input=$input\"><h4>Delete *.$fileval files</h4></a>";
                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">
    (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.


Posting Permissions

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