oxstrmb.php

Go to the documentation of this file.
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('&auml;', '&ouml;', '&uuml;', '&Auml;', '&Ouml;', '&Uuml;', '&szlig;' );
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         $iOffset = is_null( $iOffset ) ? 0 : $iOffset;
00076         return mb_strpos( $sHaystack, $sNeedle, $iOffset, $this->_sEncoding );
00077     }
00078 
00087     public function strstr( $sHaystack, $sNeedle )
00088     {
00089         // additional check according to bug in PHP 5.2.0 version
00090         if ( !$sHaystack ) {
00091             return false;
00092         }
00093         return mb_strstr($sHaystack, $sNeedle, false, $this->_sEncoding);
00094     }
00095 
00103     public function strtolower($sString)
00104     {
00105         return mb_strtolower($sString, $this->_sEncoding);
00106     }
00107 
00115     public function strtoupper($sString)
00116     {
00117         return mb_strtoupper($sString, $this->_sEncoding);
00118     }
00119 
00127     public function htmlspecialchars($sString)
00128     {
00129         return htmlspecialchars($sString, ENT_QUOTES, $this->_sEncoding);
00130     }
00131 
00139     public function htmlentities($sString)
00140     {
00141         return htmlentities($sString, ENT_QUOTES, $this->_sEncoding);
00142     }
00143 
00151     public function html_entity_decode($sString)
00152     {
00153         return html_entity_decode( $sString, ENT_QUOTES, $this->_sEncoding );
00154     }
00155 
00166     public function preg_split($sPattern, $sString, $iLimit = -1, $iFlag = 0)
00167     {
00168         return preg_split( $sPattern.'u', $sString, $iLimit, $iFlag );
00169     }
00170 
00182     public function preg_replace($aPattern, $sString, $sSubject, $iLimit = -1, $iCount = null)
00183     {
00184         if ( is_array($aPattern) ) {
00185             foreach ( $aPattern as &$sPattern) {
00186                 $sPattern = $sPattern.'u';
00187             }
00188         } else {
00189             $aPattern = $aPattern.'u';
00190         }
00191         return preg_replace( $aPattern, $sString, $sSubject, $iLimit, $iCount);
00192     }
00193 
00205     public function preg_match($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00206     {
00207         return preg_match( $sPattern.'u', $sSubject, $aMatches, $iFlags, $iOffset);
00208     }
00209 
00217     public function ucfirst($sSubject)
00218     {
00219         $sString = $this->strtoupper($this->substr($sSubject, 0, 1));
00220         return $sString . $this->substr($sSubject, 1);
00221     }
00222 
00233     public function wordwrap( $sString, $iLength = 75, $sBreak = "\n", $blCut = null )
00234     {
00235         if ( !$blCut ) {
00236             $sRegexp = "/^(.{1,{$iLength}}\r?(\s|$|\n)|.{1,{$iLength}}[^\r\s\n]*\r?(\n|\s|$))/u";
00237         } else {
00238             $sRegexp = "/^([^\s]{{$iLength}}|.{1,{$iLength}}\s)/u";
00239         }
00240 
00241         $iStrLen = mb_strlen( $sString, $this->_sEncoding );
00242         $iWraps = floor( $iStrLen / $iLength );
00243 
00244         $i = $iWraps;
00245         $sReturn = '';
00246         $aMatches = array();
00247         while ( $i > 0 ) {
00248             $iWraps = floor( mb_strlen( $sString, $this->_sEncoding ) / $iLength );
00249 
00250             $i = $iWraps;
00251             if ( preg_match( $sRegexp, $sString, $aMatches ) ) {
00252                 $sStr = $aMatches[0];
00253                 $sReturn .= preg_replace( '/\s$/s', '', $sStr ) . $sBreak;
00254                 $sString = $this->substr( $sString, mb_strlen( $sStr, $this->_sEncoding ) );
00255             } else {
00256                 break;
00257             }
00258             $i--;
00259         }
00260         $sReturn = preg_replace( "/$sBreak$/", '', $sReturn );
00261         if ($sString) {
00262             $sReturn .= $sBreak.$sString;
00263         }
00264         return $sReturn;
00265     }
00266 
00279     public function recodeEntities( $sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array() )
00280     {
00281         $aUmls = ( count( $aUmls ) > 0 ) ? array_merge( $this->_aUmls, $aUmls) : $this->_aUmls;
00282         $aUmlEntities = ( count( $aUmlEntities ) > 0 ) ? array_merge( $this->_aUmlEntities, $aUmlEntities) : $this->_aUmlEntities;
00283         return $blToHtmlEntities ? str_replace( $aUmls, $aUmlEntities, $sInput ) : str_replace( $aUmlEntities, $aUmls, $sInput );
00284     }
00285 
00293     public function hasSpecialChars( $sStr )
00294     {
00295         return $this->preg_match( "/(".implode( "|", $this->_aUmls  )."|(&amp;))/", $sStr );
00296     }
00297 
00307     public function cleanStr( $sStr, $sCleanChr = ' ' )
00308     {
00309         return $this->preg_replace( "/\"|\'|\:|\!|\?|\n|\r|\t|\xc2\x95|\xc2\xa0|;/", $sCleanChr, $sStr );
00310     }
00311 }

Generated on Tue Sep 29 16:45:13 2009 for OXID eShop CE by  doxygen 1.5.5