phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file _charset.funcs.php

Documentation is available at _charset.funcs.php

  1. <?php
  2. /**
  3.  * This file implements functions for handling charsets.
  4.  *
  5.  * This file is part of Quam Plures - {@link http://quamplures.net/}
  6.  * See also {@link https://launchpad.net/quam-plures}.
  7.  *
  8.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  9.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
  10.  *  Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://daniel.hahler.de/}.
  11.  *
  12.  *  {@internal License choice
  13.  *  - If you have received this file as part of a package, please find the license.txt file in
  14.  *    the same folder or the closest folder above for complete license terms.
  15.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  16.  *    then you must choose one of the following licenses before using the file:
  17.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  18.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  19.  *  }}}
  20.  *
  21.  *  {@internal Open Source relicensing agreement:
  22.  *  Daniel HAHLER grants Francois PLANQUE the right to license
  23.  *  Daniel HAHLER's contributions to this file and the b2evolution project
  24.  *  under any OSI approved OSS license (http://www.opensource.org/licenses/).
  25.  *  }}}
  26.  *
  27.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  28.  * @author blueyed: Daniel HAHLER.
  29.  * @author fplanque: Francois PLANQUE.
  30.  *
  31.  * @todo dh> Move this to some other directory?
  32.  *
  33.  * @package pond
  34.  */
  35. if!defined('QP_MAIN_INIT') ) die'Please, do not access this page directly.' );
  36.  
  37.  
  38. /**
  39.  * Convert special chars (like german umlauts) to ASCII characters.
  40.  *
  41.  * @todo dh> IMHO this function should not be included in a file that gets used often/always.
  42.  * @param string 
  43.  * @return string 
  44.  */
  45. function replace_special_chars$str )
  46. {
  47.     global $evo_charset;
  48.  
  49.     ifcan_convert_charsets('UTF-8'$evo_charset&& can_convert_charsets('UTF-8''ISO-8859-1'/* source */ )
  50.     {
  51.         $str convert_charset$str'UTF-8'$evo_charset );
  52.  
  53.         // TODO: add more...?!
  54.         $search array'Ä''ä''Ö''ö''Ü''ü''ß''à''ç''è''é''ì''ò''ô''ù' )// iso-8859-1
  55.         $replace array'Ae''ae''Oe''oe''Ue''ue''ss''a''c''e''e''i''o''o''u' );
  56.  
  57.         foreach$search as $k => $v )
  58.         // convert $search to UTF-8
  59.             $search[$kconvert_charset$v'UTF-8''ISO-8859-1' );
  60.         }
  61.         $str str_replace$search$replace$str );
  62.  
  63.         // Replace HTML entities
  64.         $str htmlentities$strENT_NOQUOTES'UTF-8' );
  65.     }
  66.     else
  67.     {
  68.         // Replace HTML entities only
  69.         $str htmlentities$strENT_NOQUOTES$evo_charset );
  70.     }
  71.  
  72.     // Keep only one char in entities!
  73.     $str preg_replace'/&(.).+?;/''$1'$str );
  74.     // Replace non acceptable chars
  75.     $str preg_replace'/[^A-Za-z0-9_]+/''-'$str );
  76.     // Remove '-' at start and end:
  77.     $str preg_replace'/^-+/'''$str );
  78.     $str preg_replace'/-+$/'''$str );
  79.  
  80.     return $str;
  81. }
  82.  
  83.  
  84. ?>