oxutilsstring.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxUtilsString
00007 {
00008 
00012     public function __construct()
00013     {
00014     }
00015 
00023     public function prepareCSVField($sInField)
00024     {
00025         $oStr = getStr();
00026         if ($oStr->strstr($sInField, '"')) {
00027             return '"' . str_replace('"', '""', $sInField) . '"';
00028         } elseif ($oStr->strstr($sInField, ';')) {
00029             return '"' . $sInField . '"';
00030         }
00031 
00032         return $sInField;
00033     }
00034 
00045     public function minimizeTruncateString($sString, $iLength)
00046     {
00047         //leading and ending whitespaces
00048         $sString = trim($sString);
00049         $oStr = getStr();
00050 
00051         //multiple whitespaces
00052         $sString = $oStr->preg_replace("/[ \t\n\r]+/", " ", $sString);
00053         if ($oStr->strlen($sString) > $iLength && $iLength != -1) {
00054             $sString = $oStr->substr($sString, 0, $iLength);
00055         }
00056 
00057         $sString = $oStr->preg_replace("/,+$/", "", $sString);
00058 
00059         return $sString;
00060     }
00061 
00069     public function prepareStrForSearch($sSearchStr)
00070     {
00071         $oStr = getStr();
00072         if ($oStr->hasSpecialChars($sSearchStr)) {
00073             return $oStr->recodeEntities($sSearchStr, true, array('&amp;'), array('&'));
00074         }
00075 
00076         return '';
00077     }
00078 }