Skip to content

Instantly share code, notes, and snippets.

@kate-kate
Created July 18, 2014 10:12
Show Gist options
  • Save kate-kate/4e509f4a146e6095157b to your computer and use it in GitHub Desktop.
Save kate-kate/4e509f4a146e6095157b to your computer and use it in GitHub Desktop.
public function actionFindTables()
{
$res = [];
$text = file_get_contents('zl30.html', 'web');
$rows = preg_split('/=+/', $text);
foreach ($rows as $row) {
list($title, $body) = preg_split('/-{5,}/', $row);
$html = '<h1><br />' . $title . '<br /><br /></h1>';
$html .= '<table border="1" cellspacing="0" cellpadding="4"><colgroup span="5" width="85">';
$html .= '<thead><tr><td align="left" height="17">№</td><td align="left">Part No.</td>
<td align="left">Описание</td><td align="left">Количество</td></tr></thead>';
$html .= '<tbody>';
$trs = preg_split('/\n/', $body);
for ($n = 0; isset($trs[$n]); $n++) {
if ($trs[$n]) {
$html .= '<tr>';
if (preg_match('/\s\|\s/', $trs[$n])) {
list($first, $sec) = preg_split('/\s\|\s/', $trs[$n]);
$i = preg_match('/\d+/', $first);
$html .= '<td align="left" height="17">' . $i . '</td>';
$html .= '<td align="left">' . substr($first, strlen($i) + 1) . '</td>';
$quant = preg_match('/\d+$/', $sec);
$html .= '<td align="left">' . substr($sec, 0, strlen($sec) - strlen($quant) - 1) . '</td>';
$html .= '<td align="left">' . $quant . '</td>';
} else {
print_r($trs[$n]);
exit;
}
$html .= '</tr>';
}
}
$html .= '</tbody></table>';
$res[] = [
'table' => $html,
'title' => $title
];
}
print_r($res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment