#1
  1. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    I'm using this to try and strip all the layer tags out of a very large number of html pages. However, it doesn't work. I get this:

    Warning: fopen(".","r+") - Is a directory in /usr/users1/hak/public_html/test/regex.php3 on line 15
    .
    Warning: Unable to find file identifier 0 in /usr/users1/hak/public_html/test/regex.php3 on line 21

    Warning: fopen("..","r+") - Is a directory in /usr/users1/hak/public_html/test/regex.php3 on line 15
    ..
    Warning: Unable to find file identifier 0 in /usr/users1/hak/public_html/test/regex.php3 on line 21
    1040.html1041.html1042.html1043.htmlregex.php3
    Warning: fopen("","r+") - No such file or directory in /usr/users1/hak/public_html/test/regex.php3 on line 15

    Warning: Unable to find file identifier 0 in /usr/users1/hak/public_html/test/regex.php3 on line 21

    Warning: fopen("","r+") - No such file or directory in /usr/users1/hak/public_html/test/regex.php3 on line 15

    Warning: Unable to find file identifier 0 in /usr/users1/hak/public_html/test/regex.php3 on line 21
    All done!

    I think what it is doing is stringing all the filenames together, producing an invalid filename. Please can someone tell me what's wrong with this as I have tried everything I can think of.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    <?

    ex;
    $regex_dir = opendir("/usr/users1/hak/public_html/test");
    $x = 0;
    while ($files[$x] = readdir($regex_dir)) {
    $x++;
    }
    closedir($regex_dir);

    // this puts the file names into a large array in which you can use another loop to perform the regex's on them
    $y = 0;
    while ($y <= sizeof($files)) {

    $fopen = fopen("$files[$y]", "r+");

    $pattern = "/<layer.+</layer>/";
    $replace = "";
    print preg_replace ($pattern, $replace, $files[$y]);

    fclose($fopen);

    $y++;
    }

    echo "All done!";

    ?>

    [/code]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    It's that first loop... it's concatenating all the filenames into one gigantic array slot. Here's how you should fix that:

    $x = 0;
    while(!readdir($regex_dir)) {
    $files[$x] = readdir($regex_dir);
    }

    Once again, there's no guarantee on this code -- it should only be used as a guideline.

    ------------------
    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Seattle, WA USA
    Posts
    23
    Rep Power
    0
    I did a quick test with your code to view the output on the screen...your array $files($x) works fine... But it is grabbing ., .., and any other directories in your current directory. I got this to work:

    if (ereg("*.html",$files[$y])) {
    $fopen = fopen($files[$y], "r+");
    // insert your replace code here.
    echo("Open File: ".$files[$y]);
    fclose($fopen);
    } $y++;

    Note: This code will grab only the html files.


    Carl Sweetland
  6. #4
  7. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    OK, I re-mashed the code to this:

    <?

    ex;
    $regex_dir = opendir("/usr/users1/hak/public_html/test");
    $x = 0;
    while(!readdir($regex_dir)) {
    $files[$x] = readdir($regex_dir);
    }
    closedir($regex_dir);

    // this puts the file names into a large array in which you can use another loop to perform the regex's on them
    $y = 0;
    while ($y <= sizeof($files))

    {
    if (ereg("*.html", $files[$y])) {
    $fopen = fopen($files[$y], "r+");

    $pattern = "/<layer.+</layer>/";
    $replace = "";
    print preg_replace ($pattern, $replace);

    echo("Open File: ".$files[$y]);
    fclose($fopen);
    } $y++;
    }

    echo "All done!";

    ?>

    and it seems to run OK, it prints out the All Done message at the end. However none of the files are changed: the layer tag remains! Help!

    --------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)

    [This message has been edited by alexgreg (edited August 22, 2000).]
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Seattle, WA USA
    Posts
    23
    Rep Power
    0
    I didn't test this..but first off you are increasing the value of $x. Here's your loop:

    $x = 0;
    while(!readdir($regex_dir)) {
    $files[$x] = readdir($regex_dir);
    }

    I'd bet that only the last file is changed, assuming the replacement part of the code is working.

    Add $x++;

    The code I wrote looked like this:

    $x=0;
    while ($files[$x] = readdir($regex_dir)) {
    $files[$x] = readdir($regex_dir);
    $x++;
    }

    Carl Sweetland

Similar Threads

  1. regex to strip C comments?
    By pattonme in forum Perl Programming
    Replies: 3
    Last Post: January 1st, 2004, 10:37 PM
  2. include file and strip header/footer tag
    By superspost in forum PHP Development
    Replies: 2
    Last Post: December 10th, 2003, 12:33 PM
  3. asp regex for auto close img tag
    By raw-edge in forum ASP Programming
    Replies: 0
    Last Post: December 3rd, 2003, 05:10 AM
  4. Regex pattern to return xhtml tag attributes as array
    By marcoBR in forum PHP Development
    Replies: 5
    Last Post: October 28th, 2003, 01:07 PM
  5. how to strip A HREF tag ???
    By jadakissvn in forum PHP Development
    Replies: 1
    Last Post: April 10th, 2003, 08:01 AM

IMN logo majestic logo threadwatch logo seochat tools logo