Daelan
Daelan

Reputation: 723

Any advice on parsing an OPML file with PHP so I can import the addresses into a mySql database?

I want to be able to have the user select an OPML file that contains a large number of bookmarks, then loop through each one and toss it in a mysql database.

Any direction would be much appreciated.

Upvotes: 1

Views: 674

Answers (1)

Tyler Carter
Tyler Carter

Reputation: 61577

In the end, parsing any file comes down to a few things:

  • Get the file from $_FILES
    Handling File Uploads (Documentation)
  • Load the file into a reader
    SimpleXML (Documenation)
  • Check that it is in the right format
    (This will most likely just be checking that SimpleXML didn't throw an error)
  • Loop through the data
  • Sanitize any data going into the database
  • Enter it into the database

If this is a big file, you will also want to look it things like max_upload_size and other upload size restrictions. Also, look into a way to let the user know you are working if the script takes a while to process the file.

Upvotes: 3

Related Questions