I'm trying to extract the text that is in an html table. ie.
<table>
<tr>
<td>
<font x="blah"><b>Some text </b></font>
</td>
</tr>
</table>
I need to get "Some text" out of the table and into a variable that I can manipulate. I already fopen()ed the page into a string $page. Then split() the page into an array of lines. I'm stepping through the lines and eregi()ng the lines to get what I need. It's really messy and not really working very well. The page I'm looking at has a different number of table elements at different times but always the same number of tables(4). More precisely, I need just the text from between the table data tags.
I was hoping to find an example of parsing the text out from between all the table, tr, td, and misc tags. I just need the text that would be displayed in the html table so I can redisplay it in another style. I don't have access to the database the html page is created from.
There are some extra variables and lines that don't do anything.
Thanks,
Jonas.
Files:
// Begin mls2.php parsing file
<?
error_reporting(8);
require_once("makestring.php");
require_once("inc/output_fns.php");
do_html_header("MLS Test Page");
$in_table = 0;
$in_td = 0;
$table_count = 0;
$table_data = "";
$td_start = array();
$td_end = array();
$edited_page = "";
$page = stripslashes(GetFile("http://rtr/test-mls.html"));
//$page = eregi_replace("<script[>]>(.)<\/script>", "\n Trimmed\n\n ", $page);
$edited_page = eregi_replace(" +", " ", $page);
$edited_page = eregi_replace("Copy", "replaced", $page);
$page = eregi_replace("<script[>]>(.)<\/script>", "\n Trimmed\n\n ", $page);
$page = eregi_replace("<p align=\"center\">\ [>]>(.)<!-- #EndLibraryItem -->", "\n Trimmed\n\n ", $page); // replace everthing between two points
echo $edited_page;
//$page = eregi_replace("Start a ", "\n Trimmed\n\n ", $page);
//$page = stripslashes(GetFile("http://rtr/mls117266.html"));
// echo "<table width=100% border=3>";
//$td_start = eregi_replace("<script[>]>(.)<\/script>", "\n Trimmed\n\n ", $td_start);
$td_start = split ("\n", $page);
//$td_end = split ("<\/", $page);
for ($i=0; $i< count($td_start); $i++){
//print_r(array_values($td_start));
$notags = strip_tags($td_start[$i]);
echo $i;
echo $td_start[$i];
$striped = eregi("Island of", $notags);
echo $striped;
}
echo $td_start[54]."\n\n";
echo $td_start[36]."\n\n";
echo $td_start[37]."\n\n";
echo $td_start[38]."\n\n";
echo $td_start[85]."\n\n";
echo $td_start[95]."\n\n";
echo $td_start[96]."\n\n";
echo $td_start[101]."\n\n";
echo $td_start[112]."\n\n";
?>
</body>
</html>
// <!-- End test php page. Goes in mls2.php file-->
//<!-- Begin test page date to extract text from. Put in file mls117266.html-->
<html>
<head>
<title>Hawaii Information Service: real estate, property, MLS and public records, parcel maps, business
registrations, and professional and vocational licenses online for the state of hawaii.</title>
</head>
<body bgcolor="#FFFFFF" background="/images/hiback.gif" text="#333333" link="#339999" vlink="#666666" alink="#999999">
<div align="center">
<p><img src="/images/hihead.gif" width="392" height="15"></p>
<table border="0" width="580" cellspacing="0" cellpadding="0">
<tr>
<td width="293">
<img src="pubimages/smhishead.gif" width="293" height="79" vspace="3">
</td>
<td width="287" align="left" valign="middle">
<ul>
<li><b><font face="Verdana, Arial, Geneva" size="2">Start
a <a href="default.htm">NEW</a> search</font></b></li>
<li><b><font face="Verdana, Arial, Geneva" size="2">Get
<a href="help.htm">HELP</a></font></b></li>
</ul>
</td>
</tr>
<tr>
<td colspan="2" align="center" valign="top">
<div align="center"><center>
<p> </p>
<table border="1" width="100%" cellspacing="0" cellpadding="3" bgcolor="#FFFFFF" bordercolor="#FFFFFF" bordercolorlight="#999999" bordercolordark="#FFFFFF">
<tr>
<td colspan="4" bgcolor="#339999"><div align="center"><font face="Verdana, Arial, Geneva" color="#FFFFFF"><font size="4"><b>Island of Hawaii,
North Kona District</b></font><br><b>
<font size="3">SEA VILLAGE</b>
</div>
</td>
</tr>
<tr align="center" valign="middle">
<td colspan="2"><font face="Verdana, Arial, Geneva" size="2"><b>MLS #</b>
117266</font></td>
<td colspan="2"><font face="Verdana, Arial, Geneva" size="2"><b>$305,000</b></font></td>
</tr>
<tr>
<td colspan="4">
<div align="center">
<table border="4" cellpadding="0" cellspacing="0">
<tr valign="middle">
<td align="center"><img border="3" src="http://photos.hawaiiinformation.com/WebPhotos/6/66/117266301.jpg" width="400" height="300"></td>
</tr></table>
<p><font face="Verdana, Arial, Geneva" size="1">13 photographs
are available for this listing.<br><a href="SpecificListing.asp?MLS=117266&MLSEVAL=y&ALLPICS=1">Click here to view available pictures</a>.</font></p>
</div>
</td>
</tr>
<tr>
<td colspan="4">
<div align="center">
<font face="Verdana, Arial, Geneva" size="2">
2 bedrooms & 2 baths<br>
967 sqft of living area
</font><br>
<font face="Verdana, Arial, Geneva" size="2">
Fee simple
ownership</font>
</div>
</td>
</tr>
<tr>
<td colspan="4" align="center"><font face="Verdana, Arial, Geneva" size="2"><b>Includes:</b>
appliance/unit, ceiling fan, carpet, drapes, dryer, disposal, dishwasher, floor tile, furniture/equipment, kitchenware, landscaped, linens, laundry, microwave, in ground pool, refrigerator, range, rock walls, spa, TV cable, washer
</font></td>
</tr>
<tr>
<td colspan="4" align="left"><font face="Verdana, Arial, Geneva" size="2"><b>Remarks:</b>
Terrific unit completely upgraded. Custom tile in kitchen & baths. Turn key quality furnished. Strong rental. This unit shows like a model! One mile from downtown Kona. This complex features Ocean Front Pool, Spa & Tennis Ct.</font></td>
</tr>
<tr align="center" valign="middle">
<td colspan="4">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td align="left">
</td><td>
<div align="center">
<font face="Verdana, Arial, Geneva" size="2"><b>Contact: <br>
Robert
D
Wilkinson
RA </b>
<br><b>E-mail:</b> <a href="mailto:aliib35@yahoo.com?Subject=Inquiry_about_MLS_117266_(H.I.S._Referral)">aliib35@yahoo.com</a>
</font>
</td>
<td>
<a href="http://www.coldwellaloha.com" target="4018">
<img src="/Images/custom/smlogos/offices/4018.gif" border="0" hspace="10" vspace="10" align="right"></a>
</td>
</tr>
</table>
</td>
</tr>
<tr align="center" valign="middle">
<td colspan="4"><font face="Verdana, Arial, Geneva" size="2"><b>Coldwell Banker Aloha Properties - Kona<br>(808) 329-3545</b>
<br><a href="http://www.coldwellaloha.com" target="Coldwell Banker Aloha Properties - Kona">[url]http://www.coldwellaloha.com[/url]</a>
</font>
</td>
</tr>
</table>
</center></div>
</td>
</tr>
</table>
<p align="center"> </p>
<!-- #BeginLibraryItem "/Library/footer.lbi" -->
<p align="center"><font face="Verdana, Arial, Geneva" size="2"><a href="http://www.hawaiiinformation.com/Static/subscribers.asp">REsearch™ Login</a> |
<a href="Default.htm">Hawaii Property & Information Search</a><br>
<a href="http://www.hawaiiinformation.com/Static/news/newsmain.htm">News</a> |
<a href="http://www.hawaiiinformation.com/Static/products/productlist.htm">Products and Services</a> |
<a href="http://www.hawaiiinformation.com/Static/forms/formsdir.htm">Forms and Documents</a><br>
<a href="http://www.hawaiiinformation.com/Static/about.htm">About Hawaii Information Service</a> |
<a href="http://www.hawaiiinformation.com/Static/contact.htm">Contact Us</a> |
<a href="http://www.hawaiiinformation.com/Static/siteindex.html">Site Index</a> |
<a href="http://www.hawaiiinformation.com/">Home</a></font></p>
<p align="center"><img src="/images/dividerbar.gif" width="300" height="17"><br>
<font color="#006666"><b><font face="Verdana, Arial, Geneva" size="2">Hawaii Information
Service</font></b></font><b><br>
<font face="Verdana, Arial, Geneva" size="2">www.HawaiiInformation.com<br>
</font></b></p>
<p align="center"><font face="Verdana, Arial, Geneva" size="1">MLS & public records, parcel maps, business
registrations,<br>
and professional and vocational licenses online for the State of Hawaii.</font><font face="Verdana, Arial, Geneva" size="2"><br>
<img src="/images/bar.gif" width="580" height="3" vspace="4"><br>
<font size="1" color="#006666">Copyright © 1998-1999 by MLS Hawaii, Inc.<br>
All Rights Reserved.</font></font></p>
<!-- #EndLibraryItem -->
<p align="center"><font face="Verdana, Arial, Geneva" size="1" color="#006666">This information
has been supplied by third parties and has not been independently verified<br>
by Hawaii Information Service and is, therefore, not guaranteed.</font></p>
</div>
</body>
</html>