OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxstrregular.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_sEncoding = 'ISO8859-15';
14 
20  protected $_aUmls = array( "\344", "\366", "\374", "\304", "\326", "\334", "\337" );
21 
26  protected $_aUmlEntities = array('&auml;', '&ouml;', '&uuml;', '&Auml;', '&Ouml;', '&Uuml;', '&szlig;' );
27 
33  public function __construct()
34  {
35  }
36 
44  public function strlen($sStr)
45  {
46  return strlen($sStr);
47  }
48 
58  public function substr($sStr, $iStart, $iLength = null)
59  {
60  if (is_null($iLength)) {
61  return substr($sStr, $iStart);
62  } else {
63  return substr($sStr, $iStart, $iLength);
64  }
65  }
66 
76  public function strpos($sHaystack, $sNeedle, $iOffset = null)
77  {
78  $iPos = false;
79  if ( $sHaystack && $sNeedle ) {
80  if ( is_null( $iOffset ) ) {
81  $iPos = strpos( $sHaystack, $sNeedle );
82  } else {
83  $iPos = strpos( $sHaystack, $sNeedle, $iOffset );
84  }
85  }
86  return $iPos;
87  }
88 
97  public function strstr($sHaystack, $sNeedle)
98  {
99  return strstr($sHaystack, $sNeedle);
100  }
101 
109  public function strtolower($sString)
110  {
111  return strtolower($sString);
112  }
113 
121  public function strtoupper($sString)
122  {
123  return strtoupper($sString);
124  }
125 
133  public function htmlspecialchars($sString)
134  {
135  return htmlspecialchars( $sString, ENT_QUOTES, $this->_sEncoding );
136  }
137 
145  public function htmlentities($sString)
146  {
147  return htmlentities( $sString, ENT_QUOTES, $this->_sEncoding );
148  }
149 
157  public function html_entity_decode($sString)
158  {
159  return html_entity_decode( $sString, ENT_QUOTES, $this->_sEncoding );
160  }
161 
172  public function preg_split($sPattern, $sString, $iLimit = -1, $iFlag = 0)
173  {
174  return preg_split( $sPattern, $sString, $iLimit, $iFlag );
175  }
176 
188  public function preg_replace($sPattern, $sString, $sSubject, $iLimit = -1, $iCount = null)
189  {
190  return preg_replace( $sPattern, $sString, $sSubject, $iLimit, $iCount);
191  }
192 
204  public function preg_match($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
205  {
206  return preg_match( $sPattern, $sSubject, $aMatches, $iFlags, $iOffset);
207  }
208 
220  public function preg_match_all($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
221  {
222  return preg_match_all( $sPattern, $sSubject, $aMatches, $iFlags, $iOffset);
223  }
224 
232  public function ucfirst($sSubject)
233  {
234  $sString = $this->strtoupper($this->substr($sSubject, 0, 1));
235  return $sString . $this->substr($sSubject, 1);
236  }
237 
248  public function wordwrap($sString, $iLength = 75, $sBreak = "\n", $blCut = null )
249  {
250  return wordwrap($sString, $iLength, $sBreak, $blCut);
251  }
252 
265  public function recodeEntities( $sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array() )
266  {
267  $aUmls = ( count( $aUmls ) > 0 ) ? array_merge( $this->_aUmls, $aUmls) : $this->_aUmls;
268  $aUmlEntities = ( count( $aUmlEntities ) > 0 ) ? array_merge( $this->_aUmlEntities, $aUmlEntities) : $this->_aUmlEntities;
269  return $blToHtmlEntities ? str_replace( $aUmls, $aUmlEntities, $sInput ) : str_replace( $aUmlEntities, $aUmls, $sInput );
270  }
271 
279  public function hasSpecialChars( $sStr )
280  {
281  return $this->preg_match( "/(".implode( "|", $this->_aUmls )."|(&amp;))/", $sStr );
282  }
283 
293  public function cleanStr( $sStr, $sCleanChr = ' ')
294  {
295  return $this->preg_replace( "/\n|\r|\t|\x95|\xa0|;/", $sCleanChr, $sStr );
296  }
297 
305  public function jsonEncode($data)
306  {
307  if (is_array($data)) {
308  $ret = "";
309  $blWasOne = false;
310  $blNumerical = true;
311  reset($data);
312  while ($blNumerical && (list($key) = each($data))) {
313  $blNumerical = !is_string($key);
314  }
315  if ($blNumerical) {
316  return '['. implode(',', array_map(array($this, 'jsonEncode'), $data)).']';
317  } else {
318  foreach ($data as $key => $val) {
319  if ($blWasOne) {
320  $ret .= ',';
321  } else {
322  $blWasOne = true;
323  }
324  $ret .= '"'.addslashes($key).'":'. $this->jsonEncode($val);
325  }
326  return "{".$ret."}";
327  }
328  } else {
329  return '"'.addcslashes((string)$data, "\r\n\t\"\\").'"';
330  }
331  }
332 
341  public function strip_tags( $sString, $sAllowableTags = '' )
342  {
343  if ( stripos( $sAllowableTags, '<style>' ) === false ) {
344  // strip style tags with definitions within
345  $sString = $this->preg_replace( "'<style[^>]*>.*</style>'siU", '', $sString );
346  }
347  return strip_tags( $sString, $sAllowableTags );
348  }
349 
359  public function strrcmp( $sStr1, $sStr2 )
360  {
361  return -strcmp( $sStr1, $sStr2 );
362  }
363 }