<?php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<?php
// Start output buffering to capture the actual content
ob_start();
?>
<title>TITLE</title>
</head>
<body>
<table class="chrono">
<tr>
<td><h3>HEADING</h3></td>
</tr>
</table>
<?php
// Get the actual content from the buffer
$html_content = ob_get_clean();
// Load the HTML content into a DOMDocument
$dom = new DOMDocument;
libxml_use_internal_errors(true); // To suppress errors for invalid HTML
$dom->loadHTML($html_content);
libxml_clear_errors();
// Find the <h3> tag within the <table class="chrono"> element
$xpath = new DOMXPath($dom);
$h3_tags = $xpath->query('//table[@class="chrono"]//h3');
// Extract the text content of the first <h3> tag
$h3_text = '';
if ($h3_tags->length > 0) {
$h3_text = $h3_tags->item(0)->textContent;
}
// Modify the text based on the absence of a colon
if (strpos($h3_text, ':') === false) {
$title_text = trim($h3_text) . ": abc";
} else {
$title_text = trim($h3_text);
}
?>
<script type="text/javascript">
document.title = "<?php echo htmlspecialchars($title_text); ?>";
</script>
</body>
</html>