Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 5th, 2006, 10: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?

Reply With Quote
  #2 (permalink)  
Old June 23rd, 2006, 06: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
Default

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,
Dale

Ctrl-Alt-Del
Reply With Quote
  #3 (permalink)  
Old June 23rd, 2006, 11: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
Default

Use regular expressions, start by reading the PHP manual at:
http://www.php.net/pcre

I found Andrew Watt's Beginning Regular Expressions to be a pretty good introductory book for this topic,
http://www.wrox.com/WileyCDA/WroxTit...764574892.html

HTH!

Regards,
Rich

--
Author,
Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results

http://www.catb.org/~esr/faqs/smart-questions.html
Reply With Quote
  #4 (permalink)  
Old June 27th, 2006, 03:12 AM
Authorized User
 
Join Date: Jun 2006
Location: Enschede, , Netherlands.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 10: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 16th, 2003 12:38 AM
Parsing xml file ?? bikash XML 3 September 5th, 2003 07:23 AM



All times are GMT -4. The time now is 07:23 PM.


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