[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/locales/ -> _charset.funcs.php (source)

   1  <?php
   2  /**

   3   * This file implements functions for handling charsets.

   4   *

   5   * This file is part of the evoCore framework - {@link http://evocore.net/}

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

   9   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://daniel.hahler.de/}.

  10   *

  11   * {@internal License choice

  12   * - If you have received this file as part of a package, please find the license.txt file in

  13   *   the same folder or the closest folder above for complete license terms.

  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  15   *   then you must choose one of the following licenses before using the file:

  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  18   * }}

  19   *

  20   * {@internal Open Source relicensing agreement:

  21   * Daniel HAHLER grants Francois PLANQUE the right to license

  22   * Daniel HAHLER's contributions to this file and the b2evolution project

  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  24   * }}

  25   *

  26   * @package evocore

  27   *

  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  29   * @author blueyed: Daniel HAHLER.

  30   * @author fplanque: Francois PLANQUE.

  31   *

  32   * @version $Id: _charset.funcs.php,v 1.1 2007/06/25 11:00:36 fplanque Exp $

  33   *

  34   * @todo dh> Move this to some other directory?

  35   */
  36  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  37  
  38  
  39  /**

  40   * Convert special chars (like german umlauts) to ASCII characters.

  41   *

  42   * @todo dh> IMHO this function should not be included in a file that gets used often/always.

  43   * @param string

  44   * @return string

  45   */
  46  function replace_special_chars( $str )
  47  {
  48      global $evo_charset;
  49  
  50      if( can_convert_charsets('UTF-8', $evo_charset) && can_convert_charsets('UTF-8', 'ISO-8859-1') /* source */ )
  51      {
  52          $str = convert_charset( $str, 'UTF-8', $evo_charset );
  53  
  54          // TODO: add more...?!

  55          $search = array( 'Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', 'ß', 'à', 'ç', 'è', 'é', 'ì', 'ò', 'ô', 'ù' ); // iso-8859-1

  56          $replace = array( 'Ae', 'ae', 'Oe', 'oe', 'Ue', 'ue', 'ss', 'a', 'c', 'e', 'e', 'i', 'o', 'o', 'u' );
  57  
  58          foreach( $search as $k => $v )
  59          { // convert $search to UTF-8
  60              $search[$k] = convert_charset( $v, 'UTF-8', 'ISO-8859-1' );
  61          }
  62          $str = str_replace( $search, $replace, $str );
  63  
  64          // Replace HTML entities

  65          $str = htmlentities( $str, ENT_NOQUOTES, 'UTF-8' );
  66      }
  67      else
  68      {
  69          // Replace HTML entities only

  70          $str = htmlentities( $str, ENT_NOQUOTES, $evo_charset );
  71      }
  72  
  73      // Keep only one char in entities!

  74      $str = preg_replace( '/&(.).+?;/', '$1', $str );
  75      // Replace non acceptable chars

  76      $str = preg_replace( '/[^A-Za-z0-9_]+/', '-', $str );
  77      // Remove '-' at start and end:

  78      $str = preg_replace( '/^-+/', '', $str );
  79      $str = preg_replace( '/-+$/', '', $str );
  80  
  81      return $str;
  82  }
  83  
  84  
  85  /*

  86   * $Log: _charset.funcs.php,v $

  87   * Revision 1.1  2007/06/25 11:00:36  fplanque

  88   * MODULES (refactored MVC)

  89   *

  90   * Revision 1.3  2007/04/26 00:11:02  fplanque

  91   * (c) 2007

  92   *

  93   * Revision 1.2  2006/12/15 23:31:21  fplanque

  94   * reauthorized _ in urltitles.

  95   * No breaking of legacy permalinks.

  96   * - remains the default placeholder though.

  97   *

  98   * Revision 1.1  2006/12/04 21:20:28  blueyed

  99   * Abstracted convert_special_charsets() out of urltitle_validate()

 100   */
 101  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics