- mb_convert_encoding: documentation ( source)
- end: documentation ( source)
- strip_tags: documentation ( source)
- str_replace: documentation ( source)
- explode: documentation ( source)
- mb_internal_encoding: documentation ( source)
<?php
mb_internal_encoding('UTF-8');
$html = <<< HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Test Page</title>
</head>
<body>
<p>One two Three fourfive 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));
echo end(explode("Three four", strip_tags(str_replace(' ', ' ', $html))));
echo end(explode("Three four", strip_tags(str_replace(' ', ' ', $body))));