Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Remove total TAG on PHP for XML load document

    Hi

    i have googling and seems most answers is remove title in tag but i want look for Tag

    if you are not clear with me

    for example

    Code:
    <?xml version="1.0"?>
    <books>
      <book isbn="978-1594489501">
        <title>A Thousand Splendid Suns</title>
        <author>Khaled Hosseini</author>
        <publisher>Riverhead Hardcover</publisher>
        <amazon_price>14.27</amazon_price>
      </book>
      <book isbn="978-1594489587">
        <title>The Brief Wondrous Life of Oscar Wao</title>
        <author>Junot Diaz</author>
        <publisher>Riverhead Hardcover</publisher>
        <amazon_price>14.97</amazon_price>
      </book>
      <book isbn="978-0545010221">
        <title>Harry Potter and the Deathly Hallows</title>
        <author>J. K. Rowling</author>
        <publisher>Arthur A. Levine Books</publisher>
        <amazon_price>19.24</amazon_price>
      </book>
    </books>

    so i have write php code to get xml but there is some code i dont want show some TAG in PHP and want remove TAG and save in xml

    like i want remove in that total tag line like amazon price

    Code:
    <amazon_price>19.24</amazon_price>
    <amazon_price>14.97</amazon_price>
    <amazon_price>14.27</amazon_price>

    not '19.24' like code remove child mean 'title' & leave TAG alone


    cos i have 35,000 files of XML i dont want go every xml file remove tag and save..and i want PHP do dirty job for me and allow clients upload files and let php do remove tag which we dont want

    i have been PHP for a weeks...and i love it....and sorry for my english if you dont understand...

    if you know how or example would be great or even link!!

  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    Okay, well as long as I understand this correctly.. you want to remove the entire tag and not just the value so remove all tags.. something like.

    PHP Code:
    preg_replace("#\s+<amazon_price>[^<]*</amazon_price>#i"''$xml); 
    Where $xml is the XML feed. If you just wanted to remove the value.. but I don't think you do.. you can do.

    PHP Code:
    preg_replace("#\s+<amazon_price>[^<]*</amazon_price>#"'<amazon_price></amazon_price>'$xml); 
    I hope this helps.

  • Users who have thanked Iszak for this post:

    jedistev (03-06-2009)


  •  

    Posting Permissions

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