Results 1 to 6 of 6

Thread: Delete the Records from XML using php

  1. #1
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Delete the Records from XML using php

    i want some help to Delete one or more record from xml using php script. it should load the xml file and delete the record and save again as xml.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You can do that with these 3 functions. You may need to run the preg_replace a few times or add in some other matching depending on what you are replacing.

    file_get_contents
    http://php.net/manual/en/function.file-get-contents.php
    preg_replace
    http://php.net/manual/en/function.preg-replace.php
    file_put_contents
    http://php.net/manual/en/function.file-put-contents.php
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    XML is useful to store information, but once you need to delete or change it, the process becomes much more complex. I recommend thinking about using a database. It will be harder to setup but easier to use for complex operations like this. It is possible to do this with XML, but it is harder and you might save time if you need to do this sort of thing frequently.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. The Following User Says Thank You to djr33 For This Useful Post:

    mtazam123 (08-25-2010)

  5. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    If you're set on XML, the easiest way I've found is using simpleXML. To remove entries, you need to use unset() on the node in question.

    As djr said, however, it is a very slow and inefficient method compared to a database.

  6. #5
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    thanks man
    but my requirment is to do with the xml

  7. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Did one of the answers about XML solve the problem, or do you have another question?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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