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
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 return mb_substr( $sStr, $iStart, $iLength, $this->_sEncoding );
00062 }
00063
00073 public function strpos( $sHaystack, $sNeedle, $iOffset = null )
00074 {
00075 $iPos = false;
00076 if ( $sHaystack && $sNeedle ) {
00077 $iOffset = is_null( $iOffset ) ? 0 : $iOffset;
00078 $iPos = mb_strpos( $sHaystack, $sNeedle, $iOffset, $this->_sEncoding );
00079 }
00080 return $iPos;
00081 }
00082
00091 public function strstr( $sHaystack, $sNeedle )
00092 {
00093
00094 if ( !$sHaystack ) {
00095 return false;
00096 }
00097 return mb_strstr($sHaystack, $sNeedle, false, $this->_sEncoding);
00098 }
00099
00107 public function strtolower($sString)
00108 {
00109 return mb_strtolower($sString, $this->_sEncoding);
00110 }
00111
00119 public function strtoupper($sString)
00120 {
00121 return mb_strtoupper($sString, $this->_sEncoding);
00122 }
00123
00131 public function htmlspecialchars($sString)
00132 {
00133 return htmlspecialchars($sString, ENT_QUOTES, $this->_sEncoding);
00134 }
00135
00143 public function htmlentities($sString)
00144 {
00145 return htmlentities($sString, ENT_QUOTES, $this->_sEncoding);
00146 }
00147
00155 public function html_entity_decode($sString)
00156 {
00157 return html_entity_decode( $sString, ENT_QUOTES, $this->_sEncoding );
00158 }
00159
00170 public function preg_split($sPattern, $sString, $iLimit = -1, $iFlag = 0)
00171 {
00172 return preg_split( $sPattern.'u', $sString, $iLimit, $iFlag );
00173 }
00174
00186 public function preg_replace($aPattern, $sString, $sSubject, $iLimit = -1, $iCount = null)
00187 {
00188 if ( is_array($aPattern) ) {
00189 foreach ( $aPattern as &$sPattern) {
00190 $sPattern = $sPattern.'u';
00191 }
00192 } else {
00193 $aPattern = $aPattern.'u';
00194 }
00195 return preg_replace( $aPattern, $sString, $sSubject, $iLimit, $iCount);
00196 }
00197
00209 public function preg_match($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00210 {
00211 return preg_match( $sPattern.'u', $sSubject, $aMatches, $iFlags, $iOffset);
00212 }
00213
00221 public function ucfirst($sSubject)
00222 {
00223 $sString = $this->strtoupper($this->substr($sSubject, 0, 1));
00224 return $sString . $this->substr($sSubject, 1);
00225 }
00226
00237 public function wordwrap( $sString, $iLength = 75, $sBreak = "\n", $blCut = null )
00238 {
00239 if ( !$blCut ) {
00240 $sRegexp = "/^(.{1,{$iLength}}\r?(\s|$|\n)|.{1,{$iLength}}[^\r\s\n]*\r?(\n|\s|$))/u";
00241 } else {
00242 $sRegexp = "/^([^\s]{{$iLength}}|.{1,{$iLength}}\s)/u";
00243 }
00244
00245 $iStrLen = mb_strlen( $sString, $this->_sEncoding );
00246 $iWraps = floor( $iStrLen / $iLength );
00247
00248 $i = $iWraps;
00249 $sReturn = '';
00250 $aMatches = array();
00251 while ( $i > 0 ) {
00252 $iWraps = floor( mb_strlen( $sString, $this->_sEncoding ) / $iLength );
00253
00254 $i = $iWraps;
00255 if ( preg_match( $sRegexp, $sString, $aMatches ) ) {
00256 $sStr = $aMatches[0];
00257 $sReturn .= preg_replace( '/\s$/s', '', $sStr ) . $sBreak;
00258 $sString = $this->substr( $sString, mb_strlen( $sStr, $this->_sEncoding ) );
00259 } else {
00260 break;
00261 }
00262 $i--;
00263 }
00264 $sReturn = preg_replace( "/$sBreak$/", '', $sReturn );
00265 if ($sString) {
00266 $sReturn .= $sBreak.$sString;
00267 }
00268 return $sReturn;
00269 }
00270
00283 public function recodeEntities( $sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array() )
00284 {
00285 $aUmls = ( count( $aUmls ) > 0 ) ? array_merge( $this->_aUmls, $aUmls) : $this->_aUmls;
00286 $aUmlEntities = ( count( $aUmlEntities ) > 0 ) ? array_merge( $this->_aUmlEntities, $aUmlEntities) : $this->_aUmlEntities;
00287 return $blToHtmlEntities ? str_replace( $aUmls, $aUmlEntities, $sInput ) : str_replace( $aUmlEntities, $aUmls, $sInput );
00288 }
00289
00297 public function hasSpecialChars( $sStr )
00298 {
00299 return $this->preg_match( "/(".implode( "|", $this->_aUmls )."|(&))/", $sStr );
00300 }
00301
00311 public function cleanStr( $sStr, $sCleanChr = ' ' )
00312 {
00313 return $this->preg_replace( "/\"|\'|\:|\!|\?|\n|\r|\t|\xc2\x95|\xc2\xa0|;/", $sCleanChr, $sStr );
00314 }
00315 }