• 0

Parsing data in PHP for use in MySQL?


Question

I've been assigned a term project for my database class that involves a decent amount of PHP coding. Only problem is, I've never learned PHP. For the first part, I've got a large XML file that I want to process into individual records and store in a MySQL database. The XML file is in the following format:

<pub>
	<ID>0</ID>
	<title>Regression Time Warping for Similarity Measure of Sequence</title>
	<year>2004</year>
	<booktitle>CIT</booktitle>
	<pages>826-830</pages>
	<authors>
		<author>Hansheng Lei</author>
		<author>Venu Govindaraju</author>
	</authors>
</pub>

<pub>
.
.
.
</pub>

So, each publication would have an ID number, a title, a year, a book title, the pages, and the authors.

Now, I'm obviously not asking for anybody to do it for me or anything, but can anybody point me in the right direction of where I can go to learn how to do this? I just have no idea where to even start.

Thanks!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Parsing XML is really simple in PHP. Provided you have access to SimpleXML it's just a matter of:

$tree = simplexml_load_file("blah.xml");

Then:

foreach ($tree->item as $item)
{
	mysql_query("INSERT INTO .... VALUES ($item['title'], ....)");
}

Another handy thing with PHP is if you have any questions about a function or you're looking for something in particular, you can just type http://php.net/<searchterm> and it'll redirect you to the doc page for that function.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.