[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/Text/Filter/ -> cleanascii.php (source)

   1  <?php
   2  /**
   3   * Removes some common entities and high-ascii or otherwise nonstandard
   4   * characters common in text pasted from Microsoft Word into a browser.
   5   *
   6   * This function should NOT be used on non-ASCII text; it may and probably
   7   * will butcher other character sets indescriminately.  Use it only to clean
   8   * US-ASCII (7-bit) text which you suspect (or know) may have invalid or
   9   * non-printing characters in it.
  10   *
  11   * $Horde: framework/Text_Filter/Filter/cleanascii.php,v 1.3.2.4 2006/01/01 21:28:38 jan Exp $
  12   *
  13   * Copyright 2004-2006 Jan Schneider <jan@horde.org>
  14   *
  15   * See the enclosed file COPYING for license information (LGPL). If you did
  16   * not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  17   *
  18   * @author  Jan Schneider <jan@horde.org>
  19   * @since   Horde 3.0
  20   * @package Horde_Text
  21   */
  22  class Text_Filter_cleanascii extends Text_Filter {
  23  
  24      /**
  25       * Executes any code necessary before applying the filter patterns.
  26       *
  27       * @param string $text  The text before the filtering.
  28       *
  29       * @return string  The modified text.
  30       */
  31      function preProcess($text)
  32      {
  33          if (preg_match('/|([^#]*)#.*/', $text, $regs)) {
  34              $text = $regs[1];
  35  
  36              if (!empty($text)) {
  37                  $text = $text . "\n";
  38              }
  39          }
  40  
  41          return $text;
  42      }
  43  
  44      /**
  45       * Returns a hash with replace patterns.
  46       *
  47       * @return array  Patterns hash.
  48       */
  49      function getPatterns()
  50      {
  51          /* Remove control characters. */
  52          $regexp = array('/[\x00-\x1f]+/' => '');
  53  
  54          /* The '’' entry may look wrong, depending on your editor,
  55           * but it's not - that's not really a single quote. */
  56          $replace = array(chr(150) => '-',
  57                           chr(167) => '*',
  58                           '·' => '*',
  59                           '…' => '...',
  60                           '‘' => "'",
  61                           '’' => "'",
  62                           '“' => '"',
  63                           '”' => '"',
  64                           '•' => '*',
  65                           '–' => '-',
  66                           '—' => '-',
  67                           'Ÿ' => '*',
  68                           '&#61479;' => '.',
  69                           '&#61572;' => '*',
  70                           '&#61594;' => '*',
  71                           '&#61640;' => '-',
  72                           '&#61623;' => '-',
  73                           '&#61607;' => '*',
  74                           '&#61553;' => '*',
  75                           '&#61558;' => '*',
  76                           '&#8226;' => '*',
  77                           '&#9658;' => '>',
  78                           );
  79  
  80          return array('regexp' => $regexp, 'replace' => $replace);
  81      }
  82  
  83  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7