OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxutilsstring.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  private static $_instance = null;
14 
20  public function __construct()
21  {
22  }
23 
31  public static function getInstance()
32  {
33  return oxRegistry::get("oxUtilsString");
34  }
35 
36 
44  public function prepareCSVField($sInField)
45  {
46  $oStr = getStr();
47  if ($oStr->strstr($sInField, '"')) {
48  return '"'.str_replace('"', '""', $sInField).'"';
49  } elseif ($oStr->strstr($sInField, ';')) {
50  return '"'.$sInField.'"';
51  }
52  return $sInField;
53  }
54 
65  public function minimizeTruncateString( $sString, $iLength )
66  {
67  //leading and ending whitespaces
68  $sString = trim( $sString );
69  $oStr = getStr();
70 
71  //multiple whitespaces
72  $sString = $oStr->preg_replace( "/[ \t\n\r]+/", " ", $sString );
73  if ( $oStr->strlen( $sString ) > $iLength && $iLength != -1 ) {
74  $sString = $oStr->substr( $sString, 0, $iLength );
75  }
76 
77  $sString = $oStr->preg_replace( "/,+$/", "", $sString );
78  return $sString;
79  }
80 
88  public function prepareStrForSearch($sSearchStr)
89  {
90  $oStr = getStr();
91  if ( $oStr->hasSpecialChars( $sSearchStr ) ) {
92  return $oStr->recodeEntities( $sSearchStr, true, array( '&amp;' ), array( '&' ) );
93  }
94 
95  return '';
96  }
97 }