oxutilsstring.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxUtilsString
00007 {
00013     private static $_instance = null;
00014 
00020     protected $_aUmls = array( "\344", "\366", "\374", "\304", "\326", "\334", "\337" );
00021 
00026     protected $_aUmlEntities = array('&auml;', '&ouml;', '&uuml;', '&Auml;', '&Ouml;', '&Uuml;', '&szlig;' );
00027 
00033     public static function getInstance()
00034     {
00035         // disable caching for test modules
00036         if ( defined( 'OXID_PHP_UNIT' ) ) {
00037             static $inst = array();
00038             self::$_instance = $inst[oxClassCacheKey()];
00039         }
00040 
00041         if ( !self::$_instance instanceof oxUtilsString ) {
00042 
00043 
00044             self::$_instance = oxNew( 'oxUtilsString' );
00045 
00046             if ( defined( 'OXID_PHP_UNIT' ) ) {
00047                 $inst[oxClassCacheKey()] = self::$_instance;
00048             }
00049         }
00050         return self::$_instance;
00051     }
00052 
00053 
00061     public function prepareCSVField($sInField)
00062     {
00063         if (strstr($sInField, '"')) {
00064             return '"'.str_replace('"', '""', $sInField).'"';
00065         } elseif (strstr($sInField, ';')) {
00066             return '"'.$sInField.'"';
00067         }
00068         return $sInField;
00069     }
00070 
00080     public function minimizeTruncateString( $sString, $iLength )
00081     {
00082         $sString = str_replace( ",", " ", $sString );
00083         //leading and ending whitesapces
00084         $sString = ereg_replace( "^[ \t\n\r\v]+|[ \t\n\r\v]+$", "", $sString );
00085         //multiple whitespaces
00086         $sString = ereg_replace( "[ \t\n\r\v]+", " ", $sString );
00087         if ( strlen( $sString ) > $iLength && $iLength != -1 ) {
00088             $sString = substr( $sString, 0, $iLength );
00089         }
00090         return $sString;
00091     }
00092 
00100     public function prepareStrForSearch($sSearchStr)
00101     {
00102         if ( preg_match( "/(".implode( "|", $this->_aUmls  )."|(&amp;))/", $sSearchStr ) ) {
00103             return $this->recodeEntities( $sSearchStr, true,
00104                                           $this->_aUmls + array( count( $this->_aUmls ) => '&amp;' ),
00105                                           $this->_aUmlEntities + array( count( $this->_aUmlEntities ) => '&' ) );
00106         }
00107 
00108         return '';
00109     }
00110 
00123     public function recodeEntities( $sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array() )
00124     {
00125         $aUmls = $aUmls ? $aUmls : $this->_aUmls;
00126         $aUmlEntities = $aUmlEntities ? $aUmlEntities : $this->_aUmlEntities;
00127         return $blToHtmlEntities ? str_replace( $aUmls, $aUmlEntities, $sInput ) : str_replace( $aUmlEntities, $aUmls, $sInput );
00128     }
00129 }

Generated on Thu Feb 19 15:02:22 2009 for OXID eShop CE by  doxygen 1.5.5