rexsearch /functions/functions.mb.inc.php

Language PHP Lines 122
MD5 Hash 9eba428a9e59e862c7ee18a77a418cc8
Repository https://github.com/xong/rexsearch.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
// This file defines mb-functions for backward compatibility

if(!function_exists('mb_strlen'))
{
  function mb_strlen($str, $encoding = 'UTF-8')
  {
    return strtolower($encoding) == 'utf-8' ? strlen(utf8_decode($str)) : strlen($str);
  }
}

if(!function_exists('mb_strtolower'))
{
  function mb_strtolower($str, $encoding = 'UTF-8')
  {
    return strtolower($encoding) == 'utf-8' ? strtolower(utf8_decode($str)) : strtolower($str);
  }
}

if(!function_exists('mb_internal_encoding'))
{
  function mb_internal_encoding()
  {
    return rex_lang_is_utf8() ? 'UTF-8' : 'ISO-8859-15';
  }
}

if(!function_exists('mb_detect_encoding'))
{
  function mb_detect_encoding($str)
  {
    foreach (array('UTF-8', 'ISO-8859-15', 'WINDOWS-1251') as $encoding)
    {
      $sample = @iconv($encoding, $encoding, $str);
      if(md5($sample) == md5($str))
        return $encoding;
    }
    
    return '8bit';
  }
}

/*
 * Author: Steve
 * Source: http://www.php.net/manual/de/function.json-encode.php#82904
 * Date: 01-May-2008 12:35
 */
if (!function_exists('json_encode'))
{
  function json_encode($a=false)
  {
    if (is_null($a)) return 'null';
    if ($a === false) return 'false';
    if ($a === true) return 'true';
    if (is_scalar($a))
    {
      if (is_float($a))
      {
        // Always use "." for floats.
        return floatval(str_replace(",", ".", strval($a)));
      }

      if (is_string($a))
      {
        static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
        return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
      }
      else
        return $a;
    }
    $isList = true;
    for ($i = 0, reset($a); $i < count($a); $i++, next($a))
    {
      if (key($a) !== $i)
      {
        $isList = false;
        break;
      }
    }
    $result = array();
    if ($isList)
    {
      foreach ($a as $v) $result[] = json_encode($v);
      return '[' . join(',', $result) . ']';
    }
    else
    {
      foreach ($a as $k => $v) $result[] = json_encode($k).':'.json_encode($v);
      return '{' . join(',', $result) . '}';
    }
  }
}

/*
 * Author: www at walidator dot info
 * Source: http://de.php.net/manual/de/function.json-decode.php#91216
 * Date: 30-May-2009 02:16
 */
if ( !function_exists('json_decode') ){
function json_decode($json)
{ 
    // Author: walidator.info 2009
    $comment = false;
    $out = '$x=';
   
    for ($i=0; $i<strlen($json); $i++)
    {
        if (!$comment)
        {
            if ($json[$i] == '{')        $out .= ' array(';
            else if ($json[$i] == '}')    $out .= ')';
            else if ($json[$i] == ':')    $out .= '=>';
            else                         $out .= $json[$i];           
        }
        else $out .= $json[$i];
        if ($json[$i] == '"')    $comment = !$comment;
    }
    eval($out . ';');
    return $x;
} 
} 
Back to Top