pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP pastebin - collaborative debugging tool View Help


Posted by Tom Morris on Tue 23 Oct 11:01 (modification of post by Tom Morris view diff)
report abuse | download | new post

  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($output) == 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 (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me