I'm back folks 🙁 Sorry to be such a pain in the butt grr.

Here's my question.
I want to open a flat text file, read the contents and based on user defined input via a form remove a portion of the contents of that file, then write out the file with the removed contents. I've tried various permutations of str_replace and ereg_replace without success. I think the problem lies in the fact that what I'm trying to remove is not a string, but what could be considered several strings.

It boils down to trying to open /etc/named.conf on a unix machine and removing something like say the following block of text.

zone "blah.net" {
type master;
notify yes;
file "blah.net";
};

Any ideas would be greatly appreciated. Again I apologize for coming here with the "dumb" questions 🙁

    What's your code at the moment? It may be something to do with the newlines not getting backslashed enough so they never actually get to the regex engine.

    //replaces the newline character with the literal string
    //backslash n
    str_replace("\n",'\n',$string);
    

    Hope this is all it is
    Bubble

      You have 2 options (AFAIK).

      1. Explain the pattern that these follow, and what sort of input someone would give in order to identify these. Then someone might be able to help you with a regex expression to get what you need (not me though - regex gives me headaches)

      2. Use XML (or some similar method) to encapsulate these. For instance, instead of just having

      zone "blah.net" {
      type master;
      notify yes;
      file "blah.net";
      };

      You would want to encapsulate it like:
      <zone>
      <name>blah.net</name>
      zone "blah.net" {
      type master;
      notify yes;
      file "blah.net";
      };
      </zone>

      This would make it easy to extract what you need with a regex expression. PHP also has some built in XML functions, but I have never looked at those. They might do what you need.

      I don't fully understand your scenario, but if it were me, I would be more likely to store these bits in a database, and then selectively build a page, rather than try to snip something out of it. Maybe your situation is different than I am imagining it though.

        I apologize if I haven't fully explained my scenario here 🙂

        I am writing a GUI based DNS admin tool, removing a zone from the master list called named.conf (unix box) is the last bit I need to get through.

        What someone does is the following:

        They visit a page with a simple form, one line of text input (being the zone they wish to remove), once they submit the zone for removal, the code I'm trying to build will open up /etc/named.conf search for the zone and the surrounding text and remove just that zone and the text surroudning it. Its a bit comlpicated and like you Pig, regexes give me headaches which is why I'm running into a roadblock here. I'll definately check out the XML functions built in and see if I can somehow encapsulate the text and then remoev based on that.

        Thanks.

        EDIT: Here is the code I'm trying to work with at the moment and of course does not work.

        $zone_del = <<< END

        zone "$POST[domain]" {
        type master;
        notify yes;
        file "$
        POST[domain]";
        };
        END;

        $addtemp = file_get_contents("/etc/named.conf");
        fopen("$addtemp", "r+");
        str_replace("$addtemp", "","$zone_del");
        fclose("$addtemp");

          Write a Reply...