00001 <?php
00002
00006 class oxStrMb
00007 {
00008
00014 protected $_sEncoding = 'UTF-8';
00015
00021 protected $_aUmls = array("\xc3\xa4", "\xc3\xb6", "\xc3\xbc", "\xC3\x84", "\xC3\x96", "\xC3\x9C", "\xC3\x9F");
00022
00028 protected $_aUmlEntities = array('ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß');
00029
00033 public function __construct()
00034 {
00035 }
00036
00044 public function strlen($sStr)
00045 {
00046 return mb_strlen($sStr, $this->_sEncoding);
00047 }
00048
00058 public function substr($sStr, $iStart, $iLength = null)
00059 {
00060 $iLength = is_null($iLength) ? $this->strlen($sStr) : $iLength;
00061
00062 return mb_substr($sStr, $iStart, $iLength, $this->_sEncoding);
00063 }
00064
00074 public function strpos($sHaystack, $sNeedle, $iOffset = null)
00075 {
00076 $iPos = false;
00077 if ($sHaystack && $sNeedle) {
00078 $iOffset = is_null($iOffset) ? 0 : $iOffset;
00079 $iPos = mb_strpos($sHaystack, $sNeedle, $iOffset, $this->_sEncoding);
00080 }
00081
00082 return $iPos;
00083 }
00084
00093 public function strstr($sHaystack, $sNeedle)
00094 {
00095
00096 if (!$sHaystack) {
00097 return false;
00098 }
00099
00100 return mb_strstr($sHaystack, $sNeedle, false, $this->_sEncoding);
00101 }
00102
00110 public function strtolower($sString)
00111 {
00112 return mb_strtolower($sString, $this->_sEncoding);
00113 }
00114
00122 public function strtoupper($sString)
00123 {
00124 return mb_strtoupper($sString, $this->_sEncoding);
00125 }
00126
00135 public function htmlspecialchars($sString, $iQuotStyle = ENT_QUOTES)
00136 {
00137 return htmlspecialchars($sString, $iQuotStyle, $this->_sEncoding);
00138 }
00139
00148 public function htmlentities($sString, $iQuotStyle = ENT_QUOTES)
00149 {
00150 return htmlentities($sString, $iQuotStyle, $this->_sEncoding);
00151 }
00152
00161 public function html_entity_decode($sString, $iQuotStyle = ENT_QUOTES)
00162 {
00163 return html_entity_decode($sString, $iQuotStyle, $this->_sEncoding);
00164 }
00165
00176 public function preg_split($sPattern, $sString, $iLimit = -1, $iFlag = 0)
00177 {
00178 return preg_split($sPattern . 'u', $sString, $iLimit, $iFlag);
00179 }
00180
00192 public function preg_replace($aPattern, $sString, $sSubject, $iLimit = -1, $iCount = null)
00193 {
00194 if (is_array($aPattern)) {
00195 foreach ($aPattern as &$sPattern) {
00196 $sPattern = $sPattern . 'u';
00197 }
00198 } else {
00199 $aPattern = $aPattern . 'u';
00200 }
00201
00202 return preg_replace($aPattern, $sString, $sSubject, $iLimit, $iCount);
00203 }
00204
00216 public function preg_replace_callback($pattern, $callback, $subject, $limit = -1, &$count = null)
00217 {
00218 if (is_array($pattern)) {
00219 foreach ($pattern as &$item) {
00220 $item = $item . 'u';
00221 }
00222 } else {
00223 $pattern = $pattern . 'u';
00224 }
00225
00226 return preg_replace_callback($pattern, $callback, $subject, $limit, $count);
00227 }
00228
00240 public function preg_match($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00241 {
00242 return preg_match($sPattern . 'u', $sSubject, $aMatches, $iFlags, $iOffset);
00243 }
00244
00256 public function preg_match_all($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00257 {
00258 return preg_match_all($sPattern . 'u', $sSubject, $aMatches, $iFlags, $iOffset);
00259 }
00260
00268 public function ucfirst($sSubject)
00269 {
00270 $sString = $this->strtoupper($this->substr($sSubject, 0, 1));
00271
00272 return $sString . $this->substr($sSubject, 1);
00273 }
00274
00285 public function wordwrap($sString, $iLength = 75, $sBreak = "\n", $blCut = null)
00286 {
00287 if (!$blCut) {
00288 $sRegexp = "/^(.{1,{$iLength}}\r?(\s|$|\n)|.{1,{$iLength}}[^\r\s\n]*\r?(\n|\s|$))/u";
00289 } else {
00290 $sRegexp = "/^([^\s]{{$iLength}}|.{1,{$iLength}}\s)/u";
00291 }
00292
00293 $iStrLen = mb_strlen($sString, $this->_sEncoding);
00294 $iWraps = floor($iStrLen / $iLength);
00295
00296 $i = $iWraps;
00297 $sReturn = '';
00298 $aMatches = array();
00299 while ($i > 0) {
00300 $iWraps = floor(mb_strlen($sString, $this->_sEncoding) / $iLength);
00301
00302 $i = $iWraps;
00303 if (preg_match($sRegexp, $sString, $aMatches)) {
00304 $sStr = $aMatches[0];
00305 $sReturn .= preg_replace('/\s$/s', '', $sStr) . $sBreak;
00306 $sString = $this->substr($sString, mb_strlen($sStr, $this->_sEncoding));
00307 } else {
00308 break;
00309 }
00310 $i--;
00311 }
00312 $sReturn = preg_replace("/$sBreak$/", '', $sReturn);
00313 if ($sString) {
00314 $sReturn .= $sBreak . $sString;
00315 }
00316
00317 return $sReturn;
00318 }
00319
00332 public function recodeEntities($sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array())
00333 {
00334 $aUmls = (count($aUmls) > 0) ? array_merge($this->_aUmls, $aUmls) : $this->_aUmls;
00335 $aUmlEntities = (count($aUmlEntities) > 0) ? array_merge($this->_aUmlEntities, $aUmlEntities) : $this->_aUmlEntities;
00336
00337 return $blToHtmlEntities ? str_replace($aUmls, $aUmlEntities, $sInput) : str_replace($aUmlEntities, $aUmls, $sInput);
00338 }
00339
00347 public function hasSpecialChars($sStr)
00348 {
00349 return $this->preg_match("/(" . implode("|", $this->_aUmls) . "|(&))/", $sStr);
00350 }
00351
00361 public function cleanStr($sStr, $sCleanChr = ' ')
00362 {
00363 return $this->preg_replace("/\n|\r|\t|\xc2\x95|\xc2\xa0|;/", $sCleanChr, $sStr);
00364 }
00365
00373 public function jsonEncode($data)
00374 {
00375 return json_encode($data);
00376 }
00377
00386 public function strip_tags($sString, $sAllowableTags = '')
00387 {
00388 if (stripos($sAllowableTags, '<style>') === false) {
00389
00390 $sString = $this->preg_replace("'<style[^>]*>.*</style>'siU", '', $sString);
00391 }
00392
00393 return strip_tags($sString, $sAllowableTags);
00394 }
00395
00405 public function strrcmp($sStr1, $sStr2)
00406 {
00407 return -strcmp($sStr1, $sStr2);
00408 }
00409 }