#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    How to remove words between 2 word ?


    I have the xml file with content (example):
    Hello
    <Images>
    <URL>google</URL>
    </Images>
    <Reviews>
    Good
    </Reviews>

    everybody,

    <Images>
    <URL>bing</URL>
    </Images>
    <Reviews>
    Good
    </Reviews>

    I am Nguyen
    Output:
    Hello everybody I am Nguyen
    How to remove words between <Images> and </Reviews>. Thank you very much ! Please help me
    Above example data is small. Actually, I have a large data
    Sorry for my English !
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,925
    Rep Power
    1045
    Hi,

    did you know that god kills a kitten whenever somebody tries to parse XML with regexes?

    No, seriously: What's the broader context of this task? Because I'm pretty sure there's a more intelligent (and sane) solution involving an XML parser.

    In this example, you could just kill all child elements of the containing element and then collect the text nodes.

    Comments on this post

    • ishnid agrees
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0
    $string = "Hello
    <Images>
    <URL>google</URL>
    </Images>
    <Reviews>
    Good
    </Reviews>
    everybody,

    <Images>
    <URL>bing</URL>
    </Images>
    <Reviews>
    Good
    </Reviews>
    I am Nguyen";
    $string = preg_replace("/<Images>.*?<\/Reviews>/ism"," ",$string);

    i was test at php.toolregex.com
    it result Hello everybody, I am Nguyen

    Originally Posted by kegiaumat055
    I have the xml file with content (example):


    Output:

    How to remove words between <Images> and </Reviews>. Thank you very much ! Please help me
    Above example data is small. Actually, I have a large data
    Sorry for my English !

IMN logo majestic logo threadwatch logo seochat tools logo