PHPExcel_Shared
[ class tree: PHPExcel_Shared ] [ index: PHPExcel_Shared ] [ all elements ]

Source for file String.php

Documentation is available at String.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2008 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Shared
  23.  * @copyright  Copyright (c) 2006 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.3, 2008-08-25
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_Shared_String
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_Shared
  34.  * @copyright  Copyright (c) 2006 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36. {
  37.     /**
  38.      * Convert from OpenXML escaped control character to PHP control character
  39.      * 
  40.      * Excel 2007 team:
  41.      * ----------------
  42.      * That's correct, control characters are stored directly in the shared-strings table.
  43.      * We do encode characters that cannot be represented in XML using the following escape sequence:
  44.      * _xHHHH_ where H represents a hexadecimal character in the character's value...
  45.      * So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
  46.      * element or in the shared string <t> element.
  47.      * 
  48.      * @param     string    $value    Value to unescape
  49.      * @return     string 
  50.      */
  51.     public static function ControlCharacterOOXML2PHP($value = '') {
  52.         for ($i = 0; $i <= 19; $i++) {
  53.             if ($i != 9 && $i != 10 && $i != 13) {
  54.                 $value = str_replace('_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_', chr($i), $value);
  55.             }
  56.         }
  57.  
  58.         return $value;
  59.     }
  60.     
  61.     /**
  62.      * Convert from PHP control character to OpenXML escaped control character
  63.      * 
  64.      * Excel 2007 team:
  65.      * ----------------
  66.      * That's correct, control characters are stored directly in the shared-strings table.
  67.      * We do encode characters that cannot be represented in XML using the following escape sequence:
  68.      * _xHHHH_ where H represents a hexadecimal character in the character's value...
  69.      * So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
  70.      * element or in the shared string <t> element.
  71.      * 
  72.      * @param     string    $value    Value to escape
  73.      * @return     string 
  74.      */
  75.     public static function ControlCharacterPHP2OOXML($value = '') {
  76.         for ($i = 0; $i <= 19; $i++) {
  77.             if ($i != 9 && $i != 10 && $i != 13) {
  78.                 $value = str_replace(chr($i), '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_', $value);
  79.             }
  80.         }
  81.  
  82.         return $value;
  83.     }
  84.     
  85.     /**
  86.      * Check if a string contains UTF8 data
  87.      *
  88.      * @param string $value 
  89.      * @return boolean 
  90.      */
  91.     public static function IsUTF8($value = '') {
  92.         return utf8_encode(utf8_decode($value)) === $value;
  93.     }
  94.     
  95.     /**
  96.      * Formats a numeric value as a string for output in various output writers
  97.      *
  98.      * @param mixed $value 
  99.      * @return string 
  100.      */
  101.     public static function FormatNumber($value) {
  102.         return number_format($value, 2, '.', '');
  103.     }
  104. }

Documentation generated on Mon, 25 Aug 2008 13:50:01 +0200 by phpDocumentor 1.4.1