Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
| Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 5th, 2006, 09:44 AM
Registered User
Join Date: Jun 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

  #2 (permalink)  
Old June 23rd, 2006, 05:11 AM
Registered User
Join Date: Jun 2006
Location: Richards Bay, Kwazulu Natal, South Africa.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

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,

  #3 (permalink)  
Old June 23rd, 2006, 10:09 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts

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

  #4 (permalink)  
Old June 27th, 2006, 02:12 AM
Authorized User
Join Date: Jun 2006
Location: Enschede, , Netherlands.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts

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 :) .

Similar Threads
Thread Thread Starter Forum Replies Last Post
parsing a flat file in java Rod Guteriez BOOK: Beginning Java 2 2 May 18th, 2009 09:11 AM
Help Parsing XML File Sojan80 XML 7 January 7th, 2008 06:09 PM
Parsing HTML with Regex hugh@kmcnetwork.com VB How-To 0 February 5th, 2007 05:44 PM
problem parsing html using MS.XMLHTTP awardle Classic ASP XML 1 September 15th, 2003 11:38 PM
Parsing xml file ?? bikash XML 3 September 5th, 2003 06:23 AM

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