My code pulls certain elements from an html table and lists them:
foreach($html->find('tr[align=center]') as $e)
echo strip_tags($e->innertext) . '<br>';
The output looks like this:
OPEN 91212 ACCY 2001 12 Intro Financial Accounting 3.00 Zou, Y 1957 E B12 TR02:20PM - 03:35PM 01/13/14 - 04/28/14
Here is the HTML table these items are being pulled from:
<table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="#006699">
<tr align="center" class="tableRow1Font">
<td width="7%">WAITLIST</td>
<td width="5%">91630</td>
<td width="11%">ACCY <A HREF="http://www.gwu.edu/~bulletin/ugrad/accy.html#2001" target="_blank">2001</A>
</td>
<td width="5%">10</td>
<td width="16%">Intro Financial Accounting</td>
<td width="6%">3.00</td>
<td width="8%"> Zou, Y</td>
<td width="8%"><A HREF="http://www.gwu.edu/~map/building.cfm?BLDG=DUQUES" target="_blank" >DUQUES</a> 251</td>
<td width="13%">TR<br>09:35AM - 10:50AM</td>
<td width="14%">
01/13/14 - 04/28/14
</td>
<td width="7%">
</td>
</tr>
How could I change my code to echo a comma to separate each element? I want it to look like this:
OPEN, 91212, ACCY 2001, 12, Intro Financial Accounting, 3.00, Zou, Y, 1957 E B12, TR02:20PM - 03:35PM, 01/13/14 - 04/28/14
Try
$html->find('tr[align=center] td')
Instead to loop through each td, and replace your br tag with a comma
echo strip_tags($e->innertext) . ', ';
foreach($html->find('tr[align=center]') as $e){
$str .= strip_tags($e->innertext). ",";
}
$str = trim($str, ",");//delete last ","
echo $str;