Recent Posts
None | 18 sec ago
None | 18 sec ago
None | 46 sec ago
Java | 57 sec ago
None | 59 sec ago
Java | 1 min ago
None | 1 min ago
Java | 1 min ago
JavaScript | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
By Tom Morris on the 23rd of Oct 2007 09:51:32 AM
Download |
Raw |
Embed |
Report
// tom morris - tommorris.org
// invoke with ob_start("callback"); ... ob_end_flush();
function callback($buffer) {
$output = SmartyPants($buffer);
// get the default mime type accepted by browser
$defaultmime = mimeTypeChecker($_SERVER);
// load into DOM and test
$domtest = new DOMDocument('1.0');
if (@$domtest->loadXML($smartypants) == TRUE) {
$mime = $defaultmime;
} else {
$mime = "text/html";
}
// return headers
header('Content-Type: ' . $mime . ';charset=utf-8');
return $output;
}
// uses mimeTypeChecker... thus included below. i didn't write
// this, cant remember where i took it from
function mimeTypeChecker($server) {
$mime = 'text/html';
if(strstr($server['HTTP_USER_AGENT'], 'W3C_Validator') ||
strstr($server['HTTP_USER_AGENT'], 'WDG_SiteValidator') ||
strstr($server['HTTP_USER_AGENT'], 'W3C-checklink') ||
strstr($server['HTTP_USER_AGENT'], 'Web-Sniffer') ||
strstr($server['HTTP_USER_AGENT'], 'FeedValidator') ||
strstr($server['HTTP_USER_AGENT'], 'Poodle predictor') ||
strstr($server['HTTP_USER_AGENT'], 'Leknor.com gzip tester')) {
$mime = 'application/xhtml+xml';
} else {
if(stristr($server['HTTP_ACCEPT'], 'application/xhtml+xml')) {
if(preg_match("/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i", $server['HTTP_ACCEPT'], $matches)) {
$xhtml_q = $matches[1];
if(preg_match("/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i", $server['HTTP_ACCEPT'], $matches)) {
$html_q = $matches[1];
if((float)$xhtml_q >= (float)$html_q) {
$mime = 'application/xhtml+xml';
}
}
} else {
$mime = 'application/xhtml+xml';
}
}
}
return $mime;
}
Submit a correction or amendment below.
[ previous version ] | [ difference ] | Make A New Post