00001 <?php
00002
00006 class oxStrMb
00007 {
00013 protected $_sEncoding = 'UTF-8';
00014
00020 protected $_aUmls = array( "\xc3\xa4", "\xc3\xb6", "\xc3\xbc", "\xC3\x84", "\xC3\x96", "\xC3\x9C", "\xC3\x9F" );
00021
00026 protected $_aUmlEntities = array('ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß' );
00027
00035 public function strlen($sStr)
00036 {
00037 return mb_strlen($sStr, $this->_sEncoding);
00038 }
00039
00049 public function substr( $sStr, $iStart, $iLength = null )
00050 {
00051 $iLength = is_null( $iLength ) ? $this->strlen( $sStr ) : $iLength;
00052 return mb_substr( $sStr, $iStart, $iLength, $this->_sEncoding );
00053 }
00054
00064 public function strpos( $sHaystack, $sNeedle, $iOffset = null )
00065 {
00066 $iOffset = is_null( $iOffset ) ? 0 : $iOffset;
00067 return mb_strpos( $sHaystack, $sNeedle, $iOffset, $this->_sEncoding );
00068 }
00069
00078 public function strstr( $sHaystack, $sNeedle )
00079 {
00080
00081 if ( !$sHaystack ) {
00082 return false;
00083 }
00084 return mb_strstr($sHaystack, $sNeedle, false, $this->_sEncoding);
00085 }
00086
00094 public function strtolower($sString)
00095 {
00096 return mb_strtolower($sString, $this->_sEncoding);
00097 }
00098
00106 public function strtoupper($sString)
00107 {
00108 return mb_strtoupper($sString, $this->_sEncoding);
00109 }
00110
00118 public function htmlspecialchars($sString)
00119 {
00120 return htmlspecialchars($sString, ENT_QUOTES, $this->_sEncoding);
00121 }
00122
00130 public function htmlentities($sString)
00131 {
00132 return htmlentities($sString, ENT_QUOTES, $this->_sEncoding);
00133 }
00134
00142 public function html_entity_decode($sString)
00143 {
00144 return html_entity_decode( $sString, ENT_QUOTES, $this->_sEncoding );
00145 }
00146
00157 public function preg_split($sPattern, $sString, $iLimit = -1, $iFlag = 0)
00158 {
00159 return preg_split( $sPattern.'u', $sString, $iLimit, $iFlag );
00160 }
00161
00173 public function preg_replace($aPattern, $sString, $sSubject, $iLimit = -1, $iCount = null)
00174 {
00175 if ( is_array($aPattern) ) {
00176 foreach ( $aPattern as &$sPattern) {
00177 $sPattern = $sPattern.'u';
00178 }
00179 } else {
00180 $aPattern = $aPattern.'u';
00181 }
00182 return preg_replace( $aPattern, $sString, $sSubject, $iLimit, $iCount);
00183 }
00184
00196 public function preg_match($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00197 {
00198 return preg_match( $sPattern.'u', $sSubject, $aMatches, $iFlags, $iOffset);
00199 }
00200
00208 public function ucfirst($sSubject)
00209 {
00210 $sString = $this->strtoupper($this->substr($sSubject, 0, 1));
00211 return $sString . $this->substr($sSubject, 1);
00212 }
00213
00224 public function wordwrap( $sString, $iLength = 75, $sBreak = "\n", $blCut = null )
00225 {
00226 if ( !$blCut ) {
00227 $sRegexp = "/^(.{1,{$iLength}}\r?(\s|$|\n)|.{1,{$iLength}}[^\r\s\n]*\r?(\n|\s|$))/u";
00228 } else {
00229 $sRegexp = "/^([^\s]{{$iLength}}|.{1,{$iLength}}\s)/u";
00230 }
00231
00232 $iStrLen = mb_strlen( $sString, $this->_sEncoding );
00233 $iWraps = floor( $iStrLen / $iLength );
00234
00235 $i = $iWraps;
00236 $sReturn = '';
00237 $aMatches = array();
00238 while ( $i > 0 ) {
00239 $iWraps = floor( mb_strlen( $sString, $this->_sEncoding ) / $iLength );
00240
00241 $i = $iWraps;
00242 if ( preg_match( $sRegexp, $sString, $aMatches ) ) {
00243 $sStr = $aMatches[0];
00244 $sReturn .= preg_replace( '/\s$/s', '', $sStr ) . $sBreak;
00245 $sString = $this->substr( $sString , mb_strlen( $sStr, $this->_sEncoding ) );
00246 } else {
00247 break;
00248 }
00249 $i--;
00250 }
00251 $sReturn = preg_replace( "/$sBreak$/", '', $sReturn );
00252 if ($sString) {
00253 $sReturn .= $sBreak.$sString;
00254 }
00255 return $sReturn;
00256 }
00257
00270 public function recodeEntities( $sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array() )
00271 {
00272 $aUmls = ( count( $aUmls ) > 0 ) ? array_merge( $this->_aUmls, $aUmls) : $this->_aUmls;
00273 $aUmlEntities = ( count( $aUmlEntities ) > 0 ) ? array_merge( $this->_aUmlEntities, $aUmlEntities) : $this->_aUmlEntities;
00274 return $blToHtmlEntities ? str_replace( $aUmls, $aUmlEntities, $sInput ) : str_replace( $aUmlEntities, $aUmls, $sInput );
00275 }
00276
00284 public function hasSpecialChars( $sStr )
00285 {
00286 return $this->preg_match( "/(".implode( "|", $this->_aUmls )."|(&))/", $sStr );
00287 }
00288
00298 public function cleanStr( $sStr, $sCleanChr = ' ' )
00299 {
00300 return $this->preg_replace( "/\"|\'|\:|\!|\?|\n|\r|\t|\xc2\x95|\xc2\xa0|;/", $sCleanChr, $sStr );
00301 }
00302 }