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...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Tom Morris on the 23rd of Oct 2007 09:51:32 AM Download | Raw | Embed | Report
  1. // tom morris - tommorris.org
  2. // invoke with ob_start("callback"); ... ob_end_flush();
  3. function callback($buffer) {
  4.         $buffer = str_replace("<b>", "<strong>", $buffer);
  5.         $buffer = str_replace("</b>", "</strong>", $buffer);
  6.         $buffer = str_replace("<B>", "<strong>", $buffer);
  7.         $buffer = str_replace("</B>", "</strong>", $buffer);
  8.         $buffer = str_replace("<i>", "<em>", $buffer);
  9.         $buffer = str_replace("</i>", "</em>", $buffer);
  10.         $buffer = str_replace("<I>", "<em>", $buffer);
  11.         $buffer = str_replace("</I>", "</em>", $buffer);
  12.         $output = SmartyPants($buffer);
  13.         // get the default mime type accepted by browser
  14.         $defaultmime = mimeTypeChecker($_SERVER);
  15.         // load into DOM and test
  16.         $domtest = new DOMDocument('1.0');
  17.         if (@$domtest->loadXML($smartypants) == TRUE) {
  18.           $mime = $defaultmime;
  19.         } else {
  20.           $mime = "text/html";
  21.         }
  22.         // return headers
  23.         header('Content-Type: ' . $mime . ';charset=utf-8');
  24.         header('Vary: Accept');
  25.         return $output;
  26. }
  27.  
  28. // uses mimeTypeChecker... thus included below. i didn't write
  29. // this, cant remember where i took it from
  30. function mimeTypeChecker($server) {
  31.   $mime = 'text/html';
  32.   if(strstr($server['HTTP_USER_AGENT'], 'W3C_Validator') ||
  33.   strstr($server['HTTP_USER_AGENT'], 'WDG_SiteValidator') ||
  34.   strstr($server['HTTP_USER_AGENT'], 'W3C-checklink') ||
  35.   strstr($server['HTTP_USER_AGENT'], 'Web-Sniffer') ||
  36.   strstr($server['HTTP_USER_AGENT'], 'FeedValidator') ||
  37.   strstr($server['HTTP_USER_AGENT'], 'Poodle predictor') ||
  38.   strstr($server['HTTP_USER_AGENT'], 'Leknor.com gzip tester')) {
  39.         $mime = 'application/xhtml+xml';
  40.   } else {
  41.         if(stristr($server['HTTP_ACCEPT'], 'application/xhtml+xml')) {
  42.                 if(preg_match("/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i", $server['HTTP_ACCEPT'], $matches)) {
  43.                         $xhtml_q = $matches[1];
  44.                         if(preg_match("/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i", $server['HTTP_ACCEPT'], $matches)) {
  45.                                 $html_q = $matches[1];
  46.                                 if((float)$xhtml_q >= (float)$html_q) {
  47.                                         $mime = 'application/xhtml+xml';
  48.                                 }
  49.                         }
  50.           } else {
  51.                   $mime = 'application/xhtml+xml';
  52.           }
  53.     }
  54.   }
  55. return $mime;
  56. }
Submit a correction or amendment below. [ previous version ] | [ difference ] | Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: