balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

multibyte_supplicant.php (3409B)


      1 <?php
      2 /*
      3 	A small library that adds in fallbacks for some of the PHP multibyte string
      4 	functions. Mainly inteneded to be used with Breadcrumb NavXT
      5 
      6 	Copyright 2009-2018  John Havlik  (email : john.havlik@mtekk.us)
      7 
      8     This program is free software; you can redistribute it and/or modify
      9     it under the terms of the GNU General Public License as published by
     10     the Free Software Foundation; either version 2 of the License, or
     11     (at your option) any later version.
     12 
     13     This program is distributed in the hope that it will be useful,
     14     but WITHOUT ANY WARRANTY; without even the implied warranty of
     15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16     GNU General Public License for more details.
     17 
     18     You should have received a copy of the GNU General Public License
     19     along with this program; if not, write to the Free Software
     20     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     21 */
     22 require_once(dirname(__FILE__) . '/block_direct_access.php');
     23 if(!function_exists('mb_strlen'))
     24 {
     25 	/**
     26 	 * Fallback for mb_strlen for users without multibyte support
     27 	 * 
     28 	 * @param string $string the string to determine the lenght of
     29 	 * @return int the number of characters in the string
     30 	 */
     31 	function mb_strlen($string)
     32 	{
     33 		return strlen($string);
     34 	}
     35 }
     36 if(!function_exists('mb_strpos'))
     37 {
     38 	/**
     39 	 * Fallback for mb_strpos for users without multibyte support
     40 	 * 
     41 	 * @param string $haystack the string to search within
     42 	 * @param string $needle the string to search for
     43 	 * @return mixed position of the first instances of needle, or false if needle not found
     44 	 */
     45 	function mb_strpos($haystack, $needle, $offset = 0)
     46 	{
     47 		return strpos($haystack, $needle, $offset);
     48 	}
     49 }
     50 if(!function_exists('mb_substr'))
     51 {
     52 	/**
     53 	 * Fallback for mb_substr for users without multibyte support
     54 	 * 
     55 	 * @param string $string the input string
     56 	 * @param int $start the start
     57 	 * @param int length the length of the substring
     58 	 * @return string the substring of specified length
     59 	 */
     60 	function mb_substr($string, $start, $length = 'a')
     61 	{
     62 		//This happens to be the easiest way to preserve the behavior of substr
     63 		if($length = 'a')
     64 		{
     65 			return substr($string, $start);
     66 		}
     67 		else
     68 		{
     69 			return substr($string, $start, $length);
     70 		}
     71 	}
     72 }
     73 if(!function_exists('mb_strtolower'))
     74 {
     75 	/**
     76 	 * Fallback for mb_strtolower for users without multibyte support
     77 	 * 
     78 	 * @param string $str the string to change to lowercase
     79 	 * @param string $encoding the encoding of the string
     80 	 * @return string the lowercase string
     81 	 */
     82 	function mb_strtolower($str, $encoding = 'UTF-8')
     83 	{
     84 		return strtolower($str);
     85 	}
     86 }
     87 //We need this constant to be defined, otherwise things will break
     88 if(!defined('MB_CASE_TITLE'))
     89 {
     90 	define('MB_CASE_TITLE', '1');
     91 }
     92 if(!function_exists('mb_convert_case'))
     93 {
     94 	/**
     95 	 * A very hacky fallback for mb_convert_case for users without multibyte support
     96 	 * 
     97 	 * @param string $str the string to change the case on
     98 	 * @param int $mode the mode of case convert to use
     99 	 * @param string $encoding the encoding of the string
    100 	 * @return string the case converted string
    101 	 */
    102 	function mb_convert_case($str, $mode = MB_CASE_TITLE, $encoding = 'UTF-8')
    103 	{
    104 		//Only implementing MB_CASE_TITLE
    105 		if($mode = MB_CASE_TITLE)
    106 		{
    107 			return ucwords($str);
    108 		}
    109 		return $str;
    110 	}
    111 }