p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Pro PHP (http://p2p.wrox.com/forumdisplay.php?f=96)
-   -   Parsing an html file (http://p2p.wrox.com/showthread.php?t=43505)

hydroxide June 5th, 2006 09:44 AM

Parsing an html file
How could I parse an html file that follows a pattern identical to this:
<b>Random Company Name</b><br>
Client ID: 12-23-111<br>
Processing Location: ftlauderdale, &lt;<a href="mailto:mlewis@mycompany.com">mlewis@mycompan y.com</a>&gt;<br>
 &lt;<a href="mailto:lrivera@mycompany.com">lrivera@mycomp any.com</a>&gt;<br>
Stuart, FL 34992<br>
Contact Name: Dorothy/George Johnson<br>
Contact Phone: 555 555-5555<br>
Client Original Call In Date: 05/31/06<br>
Client Original Period Begin Date: 05/24/06<br>
Client Orginal Period End Date: 05/30/06<br>
Client Orginal Check Date: 06/02/06<br>
Client Orginal Delivery Date: 06/02/06<br>
Client New Call In Date: 06/05/06<br>
Client New Period Begin Date: 05/29/06<br>
Client New Period End Date: 06/04/06<br>
Client New Check Date: 06/09/06<br>
Client New Delivery Date: 06/09/06<br>
[u]Reason for false start:</u><br>
1st False start: Client requested to change pay period from Wed 5/24- Tues 5/30 to new dates of Mon 5/29 to Sun 6/4. Also per Matt he was not aware that client's previous payroll company required a written 30 day notice prior to canceling their account.<br>
Change date: Thursday, June 01, 2006 at 16:23:12 (EDT)

With the names and numbers obviously being different in each entry. The entries are in list form like this, with hundreds of entries. How could I potentially convert this into a flat file ready for insertion into a database?

Dnigma June 23rd, 2006 05:11 AM

If I understand your situation correctly, you have a standard HTML form that you need to populate with data from your database.

If that is so, save the HTML form with place holders for the relevant data. Then run a while loop through all your records. Before you run the while loop, read the HTML form template in a variable and then in your loop do str_replace on the place holders with the relevant data from you DB. Then either save the updated variable to your DB or to file or echo to screen.

Have fun,


richard.york June 23rd, 2006 10:09 PM

Use regular expressions, start by reading the PHP manual at:

I found Andrew Watt's Beginning Regular Expressions to be a pretty good introductory book for this topic,



Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results


PKHG June 27th, 2006 02:12 AM

You should inform youself what XHTML means (HTML but conforming to XML rules) and then use it: It gives you the power of XML to parse a page :) .

All times are GMT -4. The time now is 04:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.