)/i';
$html = preg_replace($pattern, '', $html);
// 2. Also remove any standalone
Discharge Summary
if it repeats standard title
$html = preg_replace('/
\s*
\s*Discharge\s+Summary\s*<\/strong>\s*<\/div>/i', '', $html);
return trim($html);
}
// Case 1: Template 1 with Empty summary inside {{CONTENT}}
$case1 = 'Discharge Summary
Discharge Summary
Discharge Summary
Presenting Complaints :
Abdominal Pain
';
echo "=== Case 1: Template 1 with Empty summary inside {{CONTENT}} ===\n";
echo cleanHtml($case1) . "\n\n";
// Case 2: Template with Non-empty summary with doctor notes
$case2 = 'Discharge Summary
Discharge Summary
Patient admitted with fever and responded well to IV antibiotics.
Presenting Complaints :
Abdominal Pain
';
echo "=== Case 2: Non-empty summary ===\n";
echo cleanHtml($case2) . "\n";