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

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    OK, I have a very large website of about 600 pages, all the pages of which contain a <layer> tag. I want to DELETE all of these tags and anything in between them, and the closing tag. However, the layer tag has some properties, like <layer id=x vspace=0> and I want to delete these as well. So basically the regex would say "find in this file anything that starts with <layer and ends in </layer> and replace it with nothing.

    The other part is that because the site is so large, I want it to read through all of the files one by one, do its stuff, then close the file and move onto the next. I have no idea how to do the regex, let alone this! Could someone please help me out with this? Thanks very much

    --------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    79
    Rep Power
    15
    $pattern = "/<layer.+</layer>/";
    $replace = "";
    print preg_replace ($pattern, $replace, $page);

    I think that should work, try it and get back to me.

    Basil
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    51
    Rep Power
    15
    preg_replace will work just fine, although it is known to much slower than substr_replace when making significantly large text replacements.

    check out the php annotated manual for preg_replace and substr_replace. if my memory serves me correctly, there are a few annotated benchmarks on this exact subject.

    /wj
  6. #4
  7. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    OK, thanks for the regex: I now need to know how to do the program that will open each .htm or .html file in the same directory as the script, open it, perform the regex function, close the file, then move onto the next .htm or .html file. How is this done?

    Thanks,

    --------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    use opendir, readdir, closedir, and a while loop to accomplish that.

    ex;
    $regex_dir = opendir("/path/to/files");
    $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 preform the regex's on them
    $y = 0;
    while($y =< sizeof($files)) {
    regex stuff here... remember to handle the filename by $files[$y]
    $y++;
    }


    That should work... no guarantees, though.

    ------------------
    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson

Similar Threads

  1. Strip entire page except between <a> tag
    By gamew0rld in forum PHP Development
    Replies: 16
    Last Post: March 9th, 2004, 05:33 AM
  2. regex to strip C comments?
    By pattonme in forum Perl Programming
    Replies: 3
    Last Post: January 1st, 2004, 10:37 PM
  3. include file and strip header/footer tag
    By superspost in forum PHP Development
    Replies: 2
    Last Post: December 10th, 2003, 12:33 PM
  4. 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