oxutilsstring.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxUtilsString
00007 {
00013     private static $_instance = null;
00014 
00020     public function __construct()
00021     {
00022     }
00023 
00031     public static function getInstance()
00032     {
00033         return oxRegistry::get("oxUtilsString");
00034     }
00035 
00036 
00044     public function prepareCSVField($sInField)
00045     {
00046         $oStr = getStr();
00047         if ($oStr->strstr($sInField, '"')) {
00048             return '"'.str_replace('"', '""', $sInField).'"';
00049         } elseif ($oStr->strstr($sInField, ';')) {
00050             return '"'.$sInField.'"';
00051         }
00052         return $sInField;
00053     }
00054 
00065     public function minimizeTruncateString( $sString, $iLength )
00066     {
00067         //leading and ending whitespaces
00068         $sString = trim( $sString );
00069         $oStr = getStr();
00070 
00071         //multiple whitespaces
00072         $sString = $oStr->preg_replace( "/[ \t\n\r]+/", " ", $sString );
00073         if ( $oStr->strlen( $sString ) > $iLength && $iLength != -1 ) {
00074             $sString = $oStr->substr( $sString, 0, $iLength );
00075         }
00076 
00077         $sString = $oStr->preg_replace( "/,+$/", "", $sString );
00078         return $sString;
00079     }
00080 
00088     public function prepareStrForSearch($sSearchStr)
00089     {
00090         $oStr = getStr();
00091         if ( $oStr->hasSpecialChars( $sSearchStr ) ) {
00092             return $oStr->recodeEntities( $sSearchStr, true, array( '&amp;' ), array( '&' ) );
00093         }
00094 
00095         return '';
00096     }
00097 }