oxutilsstring.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxUtilsString
00007 {
00013     private static $_instance = null;
00014 
00020     public static function getInstance()
00021     {
00022         // disable caching for test modules
00023         if ( defined( 'OXID_PHP_UNIT' ) ) {
00024             static $inst = array();
00025             self::$_instance = $inst[oxClassCacheKey()];
00026         }
00027 
00028         if ( !self::$_instance instanceof oxUtilsString ) {
00029 
00030 
00031             self::$_instance = oxNew( 'oxUtilsString' );
00032 
00033             if ( defined( 'OXID_PHP_UNIT' ) ) {
00034                 $inst[oxClassCacheKey()] = self::$_instance;
00035             }
00036         }
00037         return self::$_instance;
00038     }
00039 
00040 
00048     public function prepareCSVField($sInField)
00049     {
00050         if (strstr($sInField, '"')) {
00051             return '"'.str_replace('"', '""', $sInField).'"';
00052         } elseif (strstr($sInField, ';')) {
00053             return '"'.$sInField.'"';
00054         }
00055         return $sInField;
00056     }
00057 
00067     public function minimizeTruncateString( $sString, $iLength )
00068     {
00069         $sString = str_replace( ",", " ", $sString );
00070         //leading and ending whitesapces
00071         $sString = ereg_replace( "^[ \t\n\r\v]+|[ \t\n\r\v]+$", "", $sString );
00072         //multiple whitespaces
00073         $sString = ereg_replace( "[ \t\n\r\v]+", " ", $sString );
00074         if ( strlen( $sString ) > $iLength && $iLength != -1 ) {
00075             $sString = substr( $sString, 0, $iLength );
00076         }
00077         return $sString;
00078     }
00079 
00087     public function prepareStrForSearch($sSearchStr)
00088     {
00089         if ( preg_match( "/(ä|ö|ü|Ä|Ö|Ü|ß|(&amp;))/", $sSearchStr ) ) {
00090             return str_replace( array('ä',      'ö',      'ü',      'Ä',      'Ö',      'Ü',      'ß',       '&amp;' ),
00091                                 array('&auml;', '&ouml;', '&uuml;', '&Auml;', '&Ouml;', '&Uuml;', '&szlig;', '&' ),
00092                                 $sSearchStr);
00093         }
00094 
00095         return '';
00096     }
00097 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5