Results 1 to 4 of 4
  1. #1
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    Nested Tag Replacement...????
    OK if you are a PHP Guru you may be able to help me out here...
    I have to replace some text in a script and here is what I am trying to accomplish:::

    This will replace anything in between START and END.. note the (.*?)
    $FFETADQW = preg_replace('/START.*?END/smi', '', $FFETADQW);

    So you can replace anything in a particluar DIV TAG.. (DIV=MYTAG)
    $FFETADQW = preg_replace('/<div id="MYTAG".*?<\/div>/smi', '', $FFETADQW);

    Now here is my problem...
    The tag I want to replace has several NESTED div tags inside it...
    (Example)
    <div id="MYTAG">
    Main Content...
    <div id="NESTEDTAG1">Content
    <div id="NESTEDTAG2">Content
    </div>
    </div>
    </div>

    So if I want to replace the "MYTAG" in that example with:::
    $FFETADQW = preg_replace('/<div id="MYTAG".*?<\/div>/smi', '', $FFETADQW);

    It will replace all the text in red below::::
    <div id="MYTAG">
    Main Content...
    <div id="NESTEDTAG1">Content
    <div id="NESTEDTAG2">Content
    </div>
    </div>
    </div>

    Leaving me with a messed up page... seeing as it leaves two instances of "</div>" that do not belong.....

    Note: Things I Have Tried:::
    I have tried replacing the div tags from the inside out..

    Replacing the tags inside the main tag I want to replace first
    First Replacing -- <div id="NESTEDTAG2">Content</div>
    Second Replacing -- <div id="NESTEDTAG1">Content</div>
    Third Replacing -- <div id="MYTAG">Content</div>
    Doesn't work like that... The Nested Tags do not always have the same ID or CLASS....

    I have tried:
    $FFETADQW = preg_replace('/<div id="MYTAG".*?<\/div><\/div><\/div>/smi', '', $FFETADQW);


    But since the end tags are not on a single line it doesn't replace anything...


    ----------------------------

    Any help would be appreciated
    and if this is impossible... let me know... LOL


    ----------------------------

  2. #2
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    Well I guess this is impossible huh.... LOL....

  3. #3
    ABW Ambassador best123's Avatar
    Join Date
    July 5th, 2006
    Posts
    571
    Wink
    It is possible.... you might get 10 answers if you post it in a PHP /regular expressions sub-topic, forum

    I post all my Java questions in the Java forum and I get answers instantly sometimes have to wait for just one day.

  4. #4
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    I got it..


    $FFETADQW = preg_replace('/<div id="MYTAG".*?<\/div>\n<\/div>\n<\/div>/smi' '', $FFETADQW);

  5. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. CSS Nested Div Tag Problem
    By Uncle Rico in forum Programming / Datafeeds / Tools
    Replies: 5
    Last Post: April 26th, 2008, 04:39 PM
  2. Can I put a fied tag in an include tag???
    By Doug247 in forum WebMerge (Fourthworld.com)
    Replies: 1
    Last Post: August 11th, 2003, 09:29 AM
  3. Script Tag or HTML tag?
    By bsnrjones in forum Cusimano.com Scripts
    Replies: 1
    Last Post: February 1st, 2003, 07:12 PM
  4. Smart Tag Meta Tag Not Working?
    By gettnthar in forum Suspicious Activity!
    Replies: 5
    Last Post: January 29th, 2002, 06:41 PM

Posting Permissions

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