<?php
$html = '
<html>
<head>
<title>test</title>
</head>
<body>
<p>paragraph</p>
</body>
</html>';
$tidy = tidy_parse_string($html);
$head = tidy_get_head($tidy);
echo $head->value;
?>
The above example will output:
<head>
<title>test</title>
</head>