example.php

  1. <?php
  2.  
  3. require_once('textile/classTextile.php');
  4.  
  5. function getTextile($text) {
  6. // Comillas angulares simples, dobles y flechas
  7. $text = str_replace(array("'<",">'",'"<','>"','<<','>>','<-','->'),
  8. array('&lsaquo;','&rsaquo;','&laquo;','&raquo;','&laquo;','&raquo;','&larr;','&rarr;'), $text);
  9.  
  10. // Textile
  11. $textile = new Textile();
  12. $html = $textile->TextileThis($text);
  13.  
  14. // Mostrar bordes de tablas
  15. $html = str_replace('<table', '<table style="border-collapse:collapse;" border="1" cellpadding="4" ', $html);
  16.  
  17. // Enlazar protocolo://direccion/ruta/
  18. $html = preg_replace(
  19. "~(>| )([a-zA-Z]+://([.]?[a-zA-Z0-9_/-?&%])*)(<| )~",
  20. "\\1<a target=\"_blank\" href=\"\\2\">\\2</a>\\4", $html);
  21.  
  22. // Enlazar www.algo-mas
  23. $html = preg_replace(
  24. "~(>| )(www([-]*[.]?[a-zA-Z0-9_/-?&%])*)(<| )~",
  25. "\\1<a target=\"_blank\" href=\"http://\\2\">\\2</a>\\4", $html);
  26.  
  27. $especial = array( // Modificar los caracteres especiales que da Textile
  28. '&#169;'=>'&copy;', '&#174;'=>'&reg;',
  29. '&#176;'=>'&deg;', '&#177;'=>'&plusmn;',
  30. '&#188;'=>'&frac14;', '&#189;'=>'&frac12;',
  31. '&#190;'=>'&frac34;', '&#215;'=>'&times;',
  32. '&#8211;'=>'&ndash;', '&#8212;'=>'&mdash;',
  33. '&#8216;'=>'&lsquo;', '&#8217;'=>'&rsquo;',
  34. '&#8220;'=>'&ldquo;', '&#8221;'=>'&rdquo;',
  35. '&#8230;'=>'&hellip;', '&#8482;'=>'&trade;'
  36. );
  37. $html = str_replace(array_keys($especial), array_values($especial), $html);
  38.  
  39. // Restringir ancho
  40. $html = '<div style="max-width:600px;">'."\n$html\n".'</div>';
  41.  
  42. return $html;
  43. }
  44.  

Proinf.net