所以我成功地收集了代码中的第一个scrape,但foreach循环中的二次scrape没有产生任何值。我似乎无法弄清楚我在逻辑上做错了什么。
代码段:
// Defining the basic scraping function
function scrape_between($data, $start, $end){
$data = stristr($data, $start); // Stripping all data from before $start
$data = substr($data, strlen($start)); // Stripping $start
$stop = stripos($data, $end); // Getting the position of the $end of the data to scrape
$data = substr($data, 0, $stop); // Stripping all data from after and including the $end of the data to scrape
return $data; // Returning the scraped data from the function
}
$scraped_site = curl("http://inciweb.nwcg.gov/");
$scraped_data = scrape_between($scraped_site, "<table>", "</table>");
$separate_results = explode("<tr>", $scraped_data);
$count = 0;
$info_arr = array();
foreach ($separate_results as $row) {
++$count;
$info_arr[$count] = $row;
$scraped_data2 = scrape_between($row, "<td>", "</td>");
echo $scraped_data2;
}
foreach($info_arr as $info) {
?>
<div>
<label name="fire_info" value="<?php echo $info; ?></label>
</div>
<?php
}
?>