00001 <?php
00002
00003 class oxStrMb
00004 {
00010 protected $_sEncoding = 'UTF-8';
00011
00017 protected $_aUmls = array( "\xc3\xa4", "\xc3\xb6", "\xc3\xbc", "\xC3\x84", "\xC3\x96", "\xC3\x9C", "\xC3\x9F" );
00018
00023 protected $_aUmlEntities = array('ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß' );
00024
00032 public function strlen($sStr)
00033 {
00034 return mb_strlen($sStr, $this->_sEncoding);
00035 }
00036
00046 public function substr( $sStr, $iStart, $iLength = null )
00047 {
00048 $iLength = is_null( $iLength ) ? $this->strlen( $sStr ) : $iLength;
00049 return mb_substr( $sStr, $iStart, $iLength, $this->_sEncoding );
00050 }
00051
00061 public function strpos( $sHaystack, $sNeedle, $iOffset = null )
00062 {
00063 $iOffset = is_null( $iOffset ) ? 0 : $iOffset;
00064 return mb_strpos( $sHaystack, $sNeedle, $iOffset, $this->_sEncoding );
00065 }
00066
00075 public function strstr($sHaystack, $sNeedle)
00076 {
00077 return mb_strstr($sHaystack, $sNeedle, false, $this->_sEncoding);
00078 }
00079
00087 public function strtolower($sString)
00088 {
00089 return mb_strtolower($sString, $this->_sEncoding);
00090 }
00091
00099 public function strtoupper($sString)
00100 {
00101 return mb_strtoupper($sString, $this->_sEncoding);
00102 }
00103
00112 public function htmlspecialchars($sString, $blDoubleEncode= true)
00113 {
00114 return htmlspecialchars($sString, ENT_QUOTES, $this->_sEncoding, $blDoubleEncode);
00115 }
00116
00124 public function htmlentities($sString)
00125 {
00126 return htmlentities($sString, ENT_QUOTES, $this->_sEncoding);
00127 }
00128
00136 public function html_entity_decode($sString)
00137 {
00138 return html_entity_decode( $sString, ENT_QUOTES, $this->_sEncoding );
00139 }
00140
00151 public function preg_split($sPattern, $sString, $iLimit = -1, $iFlag = 0)
00152 {
00153 return preg_split( $sPattern.'u', $sString, $iLimit, $iFlag );
00154 }
00155
00167 public function preg_replace($aPattern, $sString, $sSubject, $sLimit = -1, $iCount = null)
00168 {
00169 if ( is_array($aPattern) ) {
00170 foreach ( $aPattern as &$sPattern) {
00171 $sPattern = $sPattern.'u';
00172 }
00173 } else {
00174 $aPattern = $aPattern.'u';
00175 }
00176 return preg_replace( $aPattern, $sString, $sSubject, $sLimit, $iCount);
00177 }
00178
00190 public function preg_match($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00191 {
00192 return preg_match( $sPattern.'u', $sSubject, $aMatches, $iFlags, $iOffset);
00193 }
00194
00202 public function ucfirst($sSubject)
00203 {
00204 $sString = $this->strtoupper($this->substr($sSubject, 0, 1));
00205 return $sString . $this->substr($sSubject, 1);
00206 }
00207
00218 public function wordwrap( $sString, $iLength = 75, $sBreak = "\n", $blCut = null )
00219 {
00220 if ( !$blCut ) {
00221 $sRegexp = '/.{'.$iLength.',}\s/u';
00222 } else {
00223 $sRegexp = '/(\S{'.$iLength.'}|.{1,'.$iLength.'}\s)/u';
00224 }
00225
00226 $iStrLen = mb_strlen( $sString, $this->_sEncoding );
00227 $iWraps = floor( $iStrLen / $iLength );
00228
00229 $i = $iWraps;
00230 $sReturn = '';
00231 $aMatches = array();
00232 while ( $i > 0 ) {
00233 $iWraps = floor( mb_strlen( $sString, $this->_sEncoding ) / $iLength );
00234
00235 $i = $iWraps;
00236 if ( preg_match( $sRegexp, $sString, $aMatches ) ) {
00237 $sStr = $aMatches[0];
00238 $sReturn .= trim( $sStr ) . $sBreak;
00239 $sString = $this->substr( trim( $sString ), mb_strlen( $sStr, $this->_sEncoding ) );
00240 } else {
00241 break;
00242 }
00243 $i--;
00244 }
00245 return $sReturn.$sString;
00246 }
00247
00260 public function recodeEntities( $sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array() )
00261 {
00262 $aUmls = ( count( $aUmls ) > 0 ) ? array_merge( $this->_aUmls, $aUmls) : $this->_aUmls;
00263 $aUmlEntities = ( count( $aUmlEntities ) > 0 ) ? array_merge( $this->_aUmlEntities, $aUmlEntities) : $this->_aUmlEntities;
00264 return $blToHtmlEntities ? str_replace( $aUmls, $aUmlEntities, $sInput ) : str_replace( $aUmlEntities, $aUmls, $sInput );
00265 }
00266
00274 public function hasSpecialChars( $sStr )
00275 {
00276 return $this->preg_match( "/(".implode( "|", $this->_aUmls )."|(&))/", $sStr );
00277 }
00278
00288 public function cleanStr( $sStr, $sCleanChr = ' ' )
00289 {
00290 return $this->preg_replace( "/\"|\'|\.|\:|\!|\?|\n|\r|\t|\xc2\x95|\xc2\xa0|;/", $sCleanChr, $sStr );
00291 }
00292 }