- mb_convert_encoding: documentation ( source)
- end: documentation ( source)
- strip_tags: documentation ( source)
- explode: documentation ( source)
<?php
$html = <<< HTML
<!doctype html>
<html>
<head>
<title>Test Page</title>
<meta charset="utf-8" />
</head>
<body>
<p>One two three four five six</p>
</body>
</html>
HTML;
$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
$dom = new DOMDocument;
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$query = $xpath->query("/html/body");
$body = $dom->saveXML($query->item(0));
$body = strip_tags($body);
echo end(explode('three four', $body));