OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
oxstrregular.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_sEncoding = 'ISO8859-15';
15 
21  protected $_aUmls = array("\344", "\366", "\374", "\304", "\326", "\334", "\337");
22 
28  protected $_aUmlEntities = array('&auml;', '&ouml;', '&uuml;', '&Auml;', '&Ouml;', '&Uuml;', '&szlig;');
29 
35  public function __construct()
36  {
37  }
38 
46  public function strlen($sStr)
47  {
48  return strlen($sStr);
49  }
50 
60  public function substr($sStr, $iStart, $iLength = null)
61  {
62  if (is_null($iLength)) {
63  return substr($sStr, $iStart);
64  } else {
65  return substr($sStr, $iStart, $iLength);
66  }
67  }
68 
78  public function strpos($sHaystack, $sNeedle, $iOffset = null)
79  {
80  $iPos = false;
81  if ($sHaystack && $sNeedle) {
82  if (is_null($iOffset)) {
83  $iPos = strpos($sHaystack, $sNeedle);
84  } else {
85  $iPos = strpos($sHaystack, $sNeedle, $iOffset);
86  }
87  }
88 
89  return $iPos;
90  }
91 
100  public function strstr($sHaystack, $sNeedle)
101  {
102  return strstr($sHaystack, $sNeedle);
103  }
104 
112  public function strtolower($sString)
113  {
114  return strtolower($sString);
115  }
116 
124  public function strtoupper($sString)
125  {
126  return strtoupper($sString);
127  }
128 
137  public function htmlspecialchars($sString, $iQuotStyle = ENT_QUOTES)
138  {
139  return htmlspecialchars($sString, $iQuotStyle, $this->_sEncoding);
140  }
141 
150  public function htmlentities($sString, $iQuotStyle = ENT_QUOTES)
151  {
152  return htmlentities($sString, $iQuotStyle, $this->_sEncoding);
153  }
154 
163  public function html_entity_decode($sString, $iQuotStyle = ENT_QUOTES)
164  {
165  return html_entity_decode($sString, $iQuotStyle, $this->_sEncoding);
166  }
167 
178  public function preg_split($sPattern, $sString, $iLimit = -1, $iFlag = 0)
179  {
180  return preg_split($sPattern, $sString, $iLimit, $iFlag);
181  }
182 
194  public function preg_replace($sPattern, $sString, $sSubject, $iLimit = -1, $iCount = null)
195  {
196  return preg_replace($sPattern, $sString, $sSubject, $iLimit, $iCount);
197  }
198 
210  public function preg_replace_callback($pattern, $callback, $subject, $limit = -1, &$count = null)
211  {
212  return preg_replace_callback($pattern, $callback, $subject, $limit, $count);
213  }
214 
226  public function preg_match($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
227  {
228  return preg_match($sPattern, $sSubject, $aMatches, $iFlags, $iOffset);
229  }
230 
242  public function preg_match_all($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
243  {
244  return preg_match_all($sPattern, $sSubject, $aMatches, $iFlags, $iOffset);
245  }
246 
254  public function ucfirst($sSubject)
255  {
256  $sString = $this->strtoupper($this->substr($sSubject, 0, 1));
257 
258  return $sString . $this->substr($sSubject, 1);
259  }
260 
271  public function wordwrap($sString, $iLength = 75, $sBreak = "\n", $blCut = null)
272  {
273  return wordwrap($sString, $iLength, $sBreak, $blCut);
274  }
275 
288  public function recodeEntities($sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array())
289  {
290  $aUmls = (count($aUmls) > 0) ? array_merge($this->_aUmls, $aUmls) : $this->_aUmls;
291  $aUmlEntities = (count($aUmlEntities) > 0) ? array_merge($this->_aUmlEntities, $aUmlEntities) : $this->_aUmlEntities;
292 
293  return $blToHtmlEntities ? str_replace($aUmls, $aUmlEntities, $sInput) : str_replace($aUmlEntities, $aUmls, $sInput);
294  }
295 
303  public function hasSpecialChars($sStr)
304  {
305  return $this->preg_match("/(" . implode("|", $this->_aUmls) . "|(&amp;))/", $sStr);
306  }
307 
317  public function cleanStr($sStr, $sCleanChr = ' ')
318  {
319  return $this->preg_replace("/\n|\r|\t|\x95|\xa0|;/", $sCleanChr, $sStr);
320  }
321 
329  public function jsonEncode($data)
330  {
331  if (is_array($data)) {
332  $ret = "";
333  $blWasOne = false;
334  $blNumerical = true;
335  reset($data);
336  while ($blNumerical && (list($key) = each($data))) {
337  $blNumerical = !is_string($key);
338  }
339  if ($blNumerical) {
340  return '[' . implode(',', array_map(array($this, 'jsonEncode'), $data)) . ']';
341  } else {
342  foreach ($data as $key => $val) {
343  if ($blWasOne) {
344  $ret .= ',';
345  } else {
346  $blWasOne = true;
347  }
348  $ret .= '"' . addslashes($key) . '":' . $this->jsonEncode($val);
349  }
350 
351  return "{" . $ret . "}";
352  }
353  } else {
354  return '"' . addcslashes((string) $data, "\r\n\t\"\\") . '"';
355  }
356  }
357 
366  public function strip_tags($sString, $sAllowableTags = '')
367  {
368  if (stripos($sAllowableTags, '<style>') === false) {
369  // strip style tags with definitions within
370  $sString = $this->preg_replace("'<style[^>]*>.*</style>'siU", '', $sString);
371  }
372 
373  return strip_tags($sString, $sAllowableTags);
374  }
375 
385  public function strrcmp($sStr1, $sStr2)
386  {
387  return -strcmp($sStr1, $sStr2);
388  }
389 }