00001 <?php
00002
00006 class oxStrRegular
00007 {
00008
00014 protected $_sEncoding = 'ISO8859-15';
00015
00021 protected $_aUmls = array("\344", "\366", "\374", "\304", "\326", "\334", "\337");
00022
00028 protected $_aUmlEntities = array('ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß');
00029
00035 public function __construct()
00036 {
00037 }
00038
00046 public function strlen($sStr)
00047 {
00048 return strlen($sStr);
00049 }
00050
00060 public function substr($sStr, $iStart, $iLength = null)
00061 {
00062 if (is_null($iLength)) {
00063 return substr($sStr, $iStart);
00064 } else {
00065 return substr($sStr, $iStart, $iLength);
00066 }
00067 }
00068
00078 public function strpos($sHaystack, $sNeedle, $iOffset = null)
00079 {
00080 $iPos = false;
00081 if ($sHaystack && $sNeedle) {
00082 if (is_null($iOffset)) {
00083 $iPos = strpos($sHaystack, $sNeedle);
00084 } else {
00085 $iPos = strpos($sHaystack, $sNeedle, $iOffset);
00086 }
00087 }
00088
00089 return $iPos;
00090 }
00091
00100 public function strstr($sHaystack, $sNeedle)
00101 {
00102 return strstr($sHaystack, $sNeedle);
00103 }
00104
00112 public function strtolower($sString)
00113 {
00114 return strtolower($sString);
00115 }
00116
00124 public function strtoupper($sString)
00125 {
00126 return strtoupper($sString);
00127 }
00128
00137 public function htmlspecialchars($sString, $iQuotStyle = ENT_QUOTES)
00138 {
00139 return htmlspecialchars($sString, $iQuotStyle, $this->_sEncoding);
00140 }
00141
00150 public function htmlentities($sString, $iQuotStyle = ENT_QUOTES)
00151 {
00152 return htmlentities($sString, $iQuotStyle, $this->_sEncoding);
00153 }
00154
00163 public function html_entity_decode($sString, $iQuotStyle = ENT_QUOTES)
00164 {
00165 return html_entity_decode($sString, $iQuotStyle, $this->_sEncoding);
00166 }
00167
00178 public function preg_split($sPattern, $sString, $iLimit = -1, $iFlag = 0)
00179 {
00180 return preg_split($sPattern, $sString, $iLimit, $iFlag);
00181 }
00182
00194 public function preg_replace($sPattern, $sString, $sSubject, $iLimit = -1, $iCount = null)
00195 {
00196 return preg_replace($sPattern, $sString, $sSubject, $iLimit, $iCount);
00197 }
00198
00210 public function preg_match($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00211 {
00212 return preg_match($sPattern, $sSubject, $aMatches, $iFlags, $iOffset);
00213 }
00214
00226 public function preg_match_all($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00227 {
00228 return preg_match_all($sPattern, $sSubject, $aMatches, $iFlags, $iOffset);
00229 }
00230
00238 public function ucfirst($sSubject)
00239 {
00240 $sString = $this->strtoupper($this->substr($sSubject, 0, 1));
00241
00242 return $sString . $this->substr($sSubject, 1);
00243 }
00244
00255 public function wordwrap($sString, $iLength = 75, $sBreak = "\n", $blCut = null)
00256 {
00257 return wordwrap($sString, $iLength, $sBreak, $blCut);
00258 }
00259
00272 public function recodeEntities($sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array())
00273 {
00274 $aUmls = (count($aUmls) > 0) ? array_merge($this->_aUmls, $aUmls) : $this->_aUmls;
00275 $aUmlEntities = (count($aUmlEntities) > 0) ? array_merge($this->_aUmlEntities, $aUmlEntities) : $this->_aUmlEntities;
00276
00277 return $blToHtmlEntities ? str_replace($aUmls, $aUmlEntities, $sInput) : str_replace($aUmlEntities, $aUmls, $sInput);
00278 }
00279
00287 public function hasSpecialChars($sStr)
00288 {
00289 return $this->preg_match("/(" . implode("|", $this->_aUmls) . "|(&))/", $sStr);
00290 }
00291
00301 public function cleanStr($sStr, $sCleanChr = ' ')
00302 {
00303 return $this->preg_replace("/\n|\r|\t|\x95|\xa0|;/", $sCleanChr, $sStr);
00304 }
00305
00313 public function jsonEncode($data)
00314 {
00315 if (is_array($data)) {
00316 $ret = "";
00317 $blWasOne = false;
00318 $blNumerical = true;
00319 reset($data);
00320 while ($blNumerical && (list($key) = each($data))) {
00321 $blNumerical = !is_string($key);
00322 }
00323 if ($blNumerical) {
00324 return '[' . implode(',', array_map(array($this, 'jsonEncode'), $data)) . ']';
00325 } else {
00326 foreach ($data as $key => $val) {
00327 if ($blWasOne) {
00328 $ret .= ',';
00329 } else {
00330 $blWasOne = true;
00331 }
00332 $ret .= '"' . addslashes($key) . '":' . $this->jsonEncode($val);
00333 }
00334
00335 return "{" . $ret . "}";
00336 }
00337 } else {
00338 return '"' . addcslashes((string) $data, "\r\n\t\"\\") . '"';
00339 }
00340 }
00341
00350 public function strip_tags($sString, $sAllowableTags = '')
00351 {
00352 if (stripos($sAllowableTags, '<style>') === false) {
00353
00354 $sString = $this->preg_replace("'<style[^>]*>.*</style>'siU", '', $sString);
00355 }
00356
00357 return strip_tags($sString, $sAllowableTags);
00358 }
00359
00369 public function strrcmp($sStr1, $sStr2)
00370 {
00371 return -strcmp($sStr1, $sStr2);
00372 }
00373 }