Page 1 of 1

Looking for advice for my PHP project

Posted: Tue May 29, 2007 8:48 pm
by Mizzmazz
Hi all,

I've recently gotten back into PHP development for some personal projects. I am a bit rusty and I wanted to get some advice on the best way to proceed in building a PHP application with a MySQL database backend. The web app will run on Apache with Debian as the OS.

The basic premise of my application is this:

- Will take XML log files and parse them and enter the data into MySQL
- Users can then edit that data via the PHP web interface, using forms, etc.
- Users then output the data into HTML format using their choice of available HTML templates

My questions are this:

1. I've been away from PHP development for awhile. Are there any new open source classes or technologies I can use to easily parse the XML and get it into my MySQL database?

2. I don't have experience with XSL/XSLT, and I'm more familiar with "HTML templates" where basically anyone that knows HTML can make template and use variable substitution for data that will come from the database. Again, is there good open source code available for this?

I would rather not store the data as XML in the database, I'd much prefer to parse it and then store it in plain text format. I wan the option of not only turning it into HTML via templates, but possibly writing something to export it to other formats such as PDF.

Thanks in advance,

Mizzmazz

Posted: Tue May 29, 2007 8:56 pm
by mattkenefick
do you have a set structure for the XML you're parsing or does it have to identify how deep the XML goes , names, etc..

Either way I'm going to say use Regular Expressions to get the data. You can use them to get attribute names and whatnot as well incase you have to use this formula with any XML file given to you, then put those into an array, clear the dupes, then create your structure based on that.

When you do that, you can use those nested arrays to create a MySQL table at runtime following the structure that the particular XML file has and then have it run through the data using INSERT to fill in the table structure.


Then if you want to pull it, you can use PHP MySQL commands to get the table's field names which could then be linked up to your html template.

Say your HTML template was like

Code: Select all

<table><tr><td>
{xmlName1}</td><td>{xmlValue1}
</td></tr></table>
Then you could use str_replace and file_get_contents to replace {xmlName1} and {xmlValue1} with your MySQL SELECT Query results.


---

Its obviously a bit deeper than that. But thats the route I would go.

If you're looking for structures pre-setup, I'd check PHPClasses. I think its PHPClasses.com? Its the first one on Google.com when you search for it.

Posted: Tue May 29, 2007 10:34 pm
by Mizzmazz
mattkenefick wrote:do you have a set structure for the XML you're parsing or does it have to identify how deep the XML goes , names, etc..
It is a very formatted XML log, with lots of iterations of the same type of data. Something like this:

Code: Select all

<site hostname="www.example.com">
<options>
 <datatype string1="text" string2="text/2" string3="text/3">
 <description>lots of text data will go here</description>
</datatype>
</options>
</site>
The file is similar to that format, with many <site> tags all following the same structure.

I like the idea of using regex to grab the data.

The problem I see with coding my own str_replace/file_get_contents output generation is that there are lots of iterative HTML tags that will have to be populated and generated, so that's why I'm wondering if there's anything already out there. A quick example would be, in my template, I need table rows to be generated on the fly by the template output code. Sometimes, there will be rows (example: <tr><td>data</td></tr>) I need generated in HTML tables, but the number of rows will vary for each page, so my template output coding just got more complex.

I'll check out PHPClasses.com and see what I can find, any further input is appreciated. Thanks!