Skip to content

Commit

Permalink
Update HTMLNormalizer.php
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoSWD authored May 7, 2024
1 parent 1388aab commit a4acfe0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Infrastructure/Schedule/HTMLNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@ public function normalize(string $html): string
$html,
);
$html = html_entity_decode($html);
$html = substr($html, strpos($html, 'PROGRAMME'));
$offset = $this->cutOffOffset($html);
$html = substr($html, $offset);
$lines = preg_split('~\n~', $html, -1, PREG_SPLIT_NO_EMPTY);
$lines = array_map('trim', $lines);
$lines = array_filter($lines);
$html = implode("\n", $lines);

return strip_tags($html);
}

private function cutOffOffset(string $html): int
{
$pos = strpos($html, 'PROGRAMME');

if ($pos === false) {
$pos = strpos($html, 'Schedule');
}

return $pos ?: 0;
}
}

0 comments on commit a4acfe0

Please sign in to comment.