[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/patchwork/utf8/src/Patchwork/PHP/Shim/ -> Xml.php (source)

   1  <?php
   2  
   3  /*
   4   * Copyright (C) 2016 Nicolas Grekas - p@tchwork.com
   5   *
   6   * This library is free software; you can redistribute it and/or modify it
   7   * under the terms of the (at your option):
   8   * Apache License v2.0 (http://apache.org/licenses/LICENSE-2.0.txt), or
   9   * GNU General Public License v2.0 (http://gnu.org/licenses/gpl-2.0.txt).
  10   */
  11  
  12  namespace Patchwork\PHP\Shim;
  13  
  14  /**
  15   * @internal
  16   */
  17  class Xml
  18  {
  19      public static function utf8_encode($s)
  20      {
  21          $s .= $s;
  22          $len = strlen($s);
  23  
  24          for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
  25              switch (true) {
  26                  case $s[$i] < "\x80": $s[$j] = $s[$i]; break;
  27                  case $s[$i] < "\xC0": $s[$j] = "\xC2"; $s[++$j] = $s[$i]; break;
  28                  default: $s[$j] = "\xC3"; $s[++$j] = chr(ord($s[$i]) - 64); break;
  29              }
  30          }
  31  
  32          return substr($s, 0, $j);
  33      }
  34  
  35      public static function utf8_decode($s)
  36      {
  37          $s .= '';
  38          $len = strlen($s);
  39  
  40          for ($i = 0, $j = 0; $i < $len; ++$i, ++$j) {
  41              switch ($s[$i] & "\xF0") {
  42                  case "\xC0":
  43                  case "\xD0":
  44                      $c = (ord($s[$i] & "\x1F") << 6) | ord($s[++$i] & "\x3F");
  45                      $s[$j] = $c < 256 ? chr($c) : '?';
  46                      break;
  47  
  48                  case "\xF0": ++$i;
  49                  case "\xE0":
  50                      $s[$j] = '?';
  51                      $i += 2;
  52                      break;
  53  
  54                  default:
  55                      $s[$j] = $s[$i];
  56              }
  57          }
  58  
  59          return substr($s, 0, $j);
  60      }
  61  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1