- preg_match_all: documentation ( source)
- implode: documentation ( source)
- array_keys: documentation ( source)
- printf: documentation ( source)
<?php
$lookup = [
'#online' => 'System is operating at peak performance.',
'#performancedegradation' => 'Performance is slower than normal.',
'#directonly' => 'Traffic is bypassing Smart CDN system, and going directly to websites.'
];
$regex = '/^(?:' . implode('|', array_keys($lookup)) . ')(?=\s)/m';
$contents = <<<TEXT
#online
System is operating at peak performance.
#directonly
Traffic is bypassing Smart CDN system, and going directly to websites.
TEXT;
$matches = preg_match_all($regex, $contents, $m) ? $m[0] : [];
foreach ($matches as $keyword) {
printf(
'<div class="badge_subpage_system"><h5>%s</h5><p>%s</p></div>',
$keyword,
$lookup[$keyword]
);
echo "\n";
}