• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

include/inc.utf8checker.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003 +-----------------------------------------------------------------------------+
00004 | ILIAS open source                                                           |
00005 +-----------------------------------------------------------------------------+
00006 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007 |                                                                             |
00008 | This program is free software; you can redistribute it and/or               |
00009 | modify it under the terms of the GNU General Public License                 |
00010 | as published by the Free Software Foundation; either version 2              |
00011 | of the License, or (at your option) any later version.                      |
00012 |                                                                             |
00013 | This program is distributed in the hope that it will be useful,             |
00014 | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016 | GNU General Public License for more details.                                |
00017 |                                                                             |
00018 | You should have received a copy of the GNU General Public License           |
00019 | along with this program; if not, write to the Free Software                 |
00020 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021 +-----------------------------------------------------------------------------+
00022 */
00023 
00036 function isUTF8 ($aStr) {
00037         $field = "/^(";
00038         $field .="[\x09|\x0A|\x0D]|[\x20-\x7E]|";
00039         $field .="[\xC2-\xDF][\x80-\xBF]|";
00040         $field .="\xE0[\xA0-\xBF][\x80-\xBF]|";
00041         $field .="[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|";
00042         $field .="\xED[\x80-\x9F][\x80-\xBF]|";
00043         $field .="\xF0[\x90-\xBF][\x80-\xBF]{2}|";
00044         $field .="[\xF1-\xF3][\x80-\xBF]{3}|";
00045         $field .="\xF4[\x80-\x8F][\x80-\xBF]{2}";
00046         $field .=")*$/s";
00047         return preg_match($field, $AStr);
00048 }
00049 
00050 function seems_not_utf8($AStr)
00051 {
00052 
00053         $ptrASCII = '[\x00-\x7F]';
00054         $ptr2Octet = '[\xC2-\xDF][\x80-\xBF]';
00055         $ptr3Octet = '[\xE0-\xEF][\x80-\xBF]{2}';
00056         $ptr4Octet = '[\xF0-\xF4][\x80-\xBF]{3}';
00057         $ptr5Octet = '[\xF8-\xFB][\x80-\xBF]{4}';
00058         $ptr6Octet = '[\xFC-\xFD][\x80-\xBF]{5}';
00059 
00060         if (preg_match("/^($ptrASCII|$ptr2Octet|$ptr3Octet|$ptr4Octet|$ptr5Octet|$ptr6Octet)*$/s", $AStr))
00061         {
00062                 return true;
00063         }
00064         else
00065         {
00066                 return false;
00067         }
00068 }
00069 
00070 function getUTF8String($aStr) {
00071         if (!isUTF8($aStr)) {   
00072                 
00073                 return utf8_encode($aStr);
00074                 
00075         }
00076         return $aStr;
00077 }
00078 
00079 ?>

Generated on Fri Dec 13 2013 09:06:36 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1