我目前有一些这样的文字:
W. 50DateWorkSuggested breakTotalMondayTuesday11/1217:00-01:0020:30-21:157:15Wednesday12/1217:00-01:0019:00-19:457:15ThursdayFridaySaturday15/1216:00-23:0020:00-20:456:15Sunday16/1217:00-01:0021:00-21:457:15Total:28W. 51DateWorkSuggested breakTotalMonday17/1217:00-01:0019:00-19:457:15TuesdayWednesday19/1217:00-00:0021:00-21:456:15Thursday20/1223:00-07:0003:00-03:457:15Friday21/1223:00-07:0002:30-03:157:15SaturdaySundayTotal:28W. 52DateWorkSuggested breakTotalMondayTuesdayWednesdayThursdayFridaySaturdaySundayTotal:0W. 1DateWorkSuggested breakTotalMonday------Total:0 Total number of hours: 77:45 Schedule for Month: December
它原本看起来不同但我删除了html标签,因为它全部在表格中,
我现在想要溢出/爆炸这些数据,以便每行读取一天如下:
Monday 10/12:
Tuesday 11/12: 17:00 - 01:00
Wednesday 12/12: 17:00 - 01:00
Thursday 13/12:
Friday 14/12:
Saturday: 15/12: 16:00 - 23:00
这是第一周的一个例子,我尝试过像:
这样的代码 preg_match_all (("/Monday|Tuesday|Wednesday|Thusday|Fiday|Saturday|Sunday/"), $content, $parts );
print_r ($parts);
但实际上没有运气,所以任何帮助都会受到赞赏,
谢谢,
杰克。
HTML标记的原始代码:
<body> <table border=0 class=blackborder cellpadding=2 cellspacing=2>
<tr><td><table class=blackborder width=315><tr><td><b>W. 50</b></td><td><B>Date</B></td><td><B>Work</B></td><td><B>Suggested break</B></td><td><B>Total</B></td><tr><td></tr><tr><td>Monday</tr><tr><td>Tuesday<td>11/12</td><td>17:00-01:00</td><td>20:30-21:15</td><td>7:15</td></tr><tr><td>Wednesday<td>12/12</td><td>17:00-01:00</td><td>19:00-19:45</td><td>7:15</td></tr><tr><td>Thursday</tr><tr><td>Friday</tr><tr><td>Saturday<td>15/12</td><td>16:00-23:00</td><td>20:00-20:45</td><td>6:15</td></tr><tr><td>Sunday<td>16/12</td><td>17:00-01:00</td><td>21:00-21:45</td><td>7:15</td></td></tr><tr><td>Total:</td><td></td><td></td><td></td><td>28</td></tr></table></td><td><table class=blackborder width=315><tr><td><b>W. 51</b></td><td><B>Date</B></td><td><B>Work</B></td><td><B>Suggested break</B></td><td><B>Total</B></td><tr><td></tr><tr><td>Monday<td>17/12</td><td>17:00-01:00</td><td>19:00-19:45</td><td>7:15</td></tr><tr><td>Tuesday</tr><tr><td>Wednesday<td>19/12</td><td>17:00-00:00</td><td>21:00-21:45</td><td>6:15</td></tr><tr><td>Thursday<td>20/12</td><td>23:00-07:00</td><td>03:00-03:45</td><td>7:15</td></tr><tr><td>Friday<td>21/12</td><td>23:00-07:00</td><td>02:30-03:15</td><td>7:15</td></tr><tr><td>Saturday</tr><tr><td>Sunday</td></tr><tr><td>Total:</td><td></td><td></td><td></td><td>28</td></tr></table></td></tr><tr><td><table class=blackborder width=315><tr><td><b>W. 52</b></td><td><B>Date</B></td><td><B>Work</B></td><td><B>Suggested break</B></td><td><B>Total</B></td><tr><td></tr><tr><td>Monday</tr><tr><td>Tuesday</tr><tr><td>Wednesday</tr><tr><td>Thursday</tr><tr><td>Friday</tr><tr><td>Saturday</tr><tr><td>Sunday</td></tr><tr><td>Total:</td><td></td><td></td><td></td><td>0</td></tr></table></td><td><table class=blackborder width=315><tr><td><b>W. 1</b></td><td><B>Date</B></td><td><B>Work</B></td><td><B>Suggested break</B></td><td><B>Total</B></td><tr><td></tr><tr><td>Monday</td></tr><tr><td>-</td></tr><tr><td>-</td></tr><tr><td>-</td></tr><tr><td>-</td></tr><tr><td>-</td></tr><tr><td>-</td></tr><tr><td>Total:</td><td></td><td></td><td></td><td>0</td></tr></table> </td> </tr> <tr> <td colspan=2> <b>Total number of hours:</b> 77:45<br> </td> </tr> </table> </body>
答案 0 :(得分:1)
好吧,我可以用正则表达式获得一天和时间
$str = 'W. 50DateWorkSuggested breakTotalMondayTuesday11/1217:00-01:0020:30-21:157:15Wednesday12/1217:00-01:0019:00-19:457:15ThursdayFridaySaturday15/1216:00-23:0020:00-20:456:15Sunday16/1217:00-01:0021:00-21:457:15Total:28W. 51DateWorkSuggested breakTotalMonday17/1217:00-01:0019:00-19:457:15TuesdayWednesday19/1217:00-00:0021:00-21:456:15Thursday20/1223:00-07:0003:00-03:457:15Friday21/1223:00-07:0002:30-03:157:15SaturdaySundayTotal:28W. 52DateWorkSuggested breakTotalMondayTuesdayWednesdayThursdayFridaySaturdaySundayTotal:0W. 1DateWorkSuggested breakTotalMonday------Total:0 Total number of hours: 77:45 Schedule for Month: December';
$ptr = "/(?P<day>:Monday|Tuesday|Wednesday|Thusday|Fiday|Saturday|Sunday?)(?P<time>([0-9:\/\- ]?)+)/";
preg_match_all($ptr, $str, $data);
echo '<pre>';
print_r($data);
echo '</pre>';
输出将是这样的
Array
(
[0] => Array
(
[0] => Tuesday11/1217:00-01:0020:30-21:157:15
[1] => Wednesday12/1217:00-01:0019:00-19:457:15
[2] => Saturday15/1216:00-23:0020:00-20:456:15
[3] => Sunday16/1217:00-01:0021:00-21:457:15
[4] => Tuesday
[5] => Wednesday19/1217:00-00:0021:00-21:456:15
[6] => Saturday
[7] => Sunday
[8] => Tuesday
[9] => Wednesday
[10] => Saturday
[11] => Sunday
)
[day] => Array
(
[0] => Tuesday
[1] => Wednesday
[2] => Saturday
[3] => Sunday
[4] => Tuesday
[5] => Wednesday
[6] => Saturday
[7] => Sunday
[8] => Tuesday
[9] => Wednesday
[10] => Saturday
[11] => Sunday
)
[1] => Array
(
[0] => Tuesday
[1] => Wednesday
[2] => Saturday
[3] => Sunday
[4] => Tuesday
[5] => Wednesday
[6] => Saturday
[7] => Sunday
[8] => Tuesday
[9] => Wednesday
[10] => Saturday
[11] => Sunday
)
[time] => Array
(
[0] => 11/1217:00-01:0020:30-21:157:15
[1] => 12/1217:00-01:0019:00-19:457:15
[2] => 15/1216:00-23:0020:00-20:456:15
[3] => 16/1217:00-01:0021:00-21:457:15
[4] =>
[5] => 19/1217:00-00:0021:00-21:456:15
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
)
[2] => Array
(
[0] => 11/1217:00-01:0020:30-21:157:15
[1] => 12/1217:00-01:0019:00-19:457:15
[2] => 15/1216:00-23:0020:00-20:456:15
[3] => 16/1217:00-01:0021:00-21:457:15
[4] =>
[5] => 19/1217:00-00:0021:00-21:456:15
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
)
[3] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
)
)
然后你可以循环使数据变得更好;)