oxstrregular.php

Go to the documentation of this file.
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('&auml;', '&ouml;', '&uuml;', '&Auml;', '&Ouml;', '&Uuml;', '&szlig;');
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_replace_callback($pattern, $callback, $subject, $limit = -1, &$count = null)
00211     {
00212         return preg_replace_callback($pattern, $callback, $subject, $limit, $count);
00213     }
00214 
00226     public function preg_match($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00227     {
00228         return preg_match($sPattern, $sSubject, $aMatches, $iFlags, $iOffset);
00229     }
00230 
00242     public function preg_match_all($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00243     {
00244         return preg_match_all($sPattern, $sSubject, $aMatches, $iFlags, $iOffset);
00245     }
00246 
00254     public function ucfirst($sSubject)
00255     {
00256         $sString = $this->strtoupper($this->substr($sSubject, 0, 1));
00257 
00258         return $sString . $this->substr($sSubject, 1);
00259     }
00260 
00271     public function wordwrap($sString, $iLength = 75, $sBreak = "\n", $blCut = null)
00272     {
00273         return wordwrap($sString, $iLength, $sBreak, $blCut);
00274     }
00275 
00288     public function recodeEntities($sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array())
00289     {
00290         $aUmls = (count($aUmls) > 0) ? array_merge($this->_aUmls, $aUmls) : $this->_aUmls;
00291         $aUmlEntities = (count($aUmlEntities) > 0) ? array_merge($this->_aUmlEntities, $aUmlEntities) : $this->_aUmlEntities;
00292 
00293         return $blToHtmlEntities ? str_replace($aUmls, $aUmlEntities, $sInput) : str_replace($aUmlEntities, $aUmls, $sInput);
00294     }
00295 
00303     public function hasSpecialChars($sStr)
00304     {
00305         return $this->preg_match("/(" . implode("|", $this->_aUmls) . "|(&amp;))/", $sStr);
00306     }
00307 
00317     public function cleanStr($sStr, $sCleanChr = ' ')
00318     {
00319         return $this->preg_replace("/\n|\r|\t|\x95|\xa0|;/", $sCleanChr, $sStr);
00320     }
00321 
00329     public function jsonEncode($data)
00330     {
00331         if (is_array($data)) {
00332             $ret = "";
00333             $blWasOne = false;
00334             $blNumerical = true;
00335             reset($data);
00336             while ($blNumerical && (list($key) = each($data))) {
00337                 $blNumerical = !is_string($key);
00338             }
00339             if ($blNumerical) {
00340                 return '[' . implode(',', array_map(array($this, 'jsonEncode'), $data)) . ']';
00341             } else {
00342                 foreach ($data as $key => $val) {
00343                     if ($blWasOne) {
00344                         $ret .= ',';
00345                     } else {
00346                         $blWasOne = true;
00347                     }
00348                     $ret .= '"' . addslashes($key) . '":' . $this->jsonEncode($val);
00349                 }
00350 
00351                 return "{" . $ret . "}";
00352             }
00353         } else {
00354             return '"' . addcslashes((string) $data, "\r\n\t\"\\") . '"';
00355         }
00356     }
00357 
00366     public function strip_tags($sString, $sAllowableTags = '')
00367     {
00368         if (stripos($sAllowableTags, '<style>') === false) {
00369             // strip style tags with definitions within
00370             $sString = $this->preg_replace("'<style[^>]*>.*</style>'siU", '', $sString);
00371         }
00372 
00373         return strip_tags($sString, $sAllowableTags);
00374     }
00375 
00385     public function strrcmp($sStr1, $sStr2)
00386     {
00387         return -strcmp($sStr1, $sStr2);
00388     }
00389 }