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 
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         return mb_strstr($sHaystack, $sNeedle, false, $this->_sEncoding);
00081     }
00082 
00090     public function strtolower($sString)
00091     {
00092         return mb_strtolower($sString, $this->_sEncoding);
00093     }
00094 
00102     public function strtoupper($sString)
00103     {
00104         return mb_strtoupper($sString, $this->_sEncoding);
00105     }
00106 
00114     public function htmlspecialchars($sString)
00115     {
00116         return htmlspecialchars($sString, ENT_QUOTES, $this->_sEncoding);
00117     }
00118 
00126     public function htmlentities($sString)
00127     {
00128         return htmlentities($sString, ENT_QUOTES, $this->_sEncoding);
00129     }
00130 
00138     public function html_entity_decode($sString)
00139     {
00140         return html_entity_decode( $sString, ENT_QUOTES, $this->_sEncoding );
00141     }
00142 
00153     public function preg_split($sPattern, $sString, $iLimit = -1, $iFlag = 0)
00154     {
00155         return preg_split( $sPattern.'u', $sString, $iLimit, $iFlag );
00156     }
00157 
00169     public function preg_replace($aPattern, $sString, $sSubject, $iLimit = -1, $iCount = null)
00170     {
00171         if ( is_array($aPattern) ) {
00172             foreach ( $aPattern as &$sPattern) {
00173                 $sPattern = $sPattern.'u';
00174             }
00175         } else {
00176             $aPattern = $aPattern.'u';
00177         }
00178         return preg_replace( $aPattern, $sString, $sSubject, $iLimit, $iCount);
00179     }
00180 
00192     public function preg_match($sPattern, $sSubject, &$aMatches = null, $iFlags = null, $iOffset = null)
00193     {
00194         return preg_match( $sPattern.'u', $sSubject, $aMatches, $iFlags, $iOffset);
00195     }
00196 
00204     public function ucfirst($sSubject)
00205     {
00206         $sString = $this->strtoupper($this->substr($sSubject, 0, 1));
00207         return $sString . $this->substr($sSubject, 1);
00208     }
00209 
00220     public function wordwrap( $sString, $iLength = 75, $sBreak = "\n", $blCut = null )
00221     {
00222         if ( !$blCut ) {
00223             $sRegexp = "/^(.{1,{$iLength}}\r?(\s|$|\n)|.{1,{$iLength}}[^\r\s\n]*\r?(\n|\s|$))/u";
00224         } else {
00225             $sRegexp = "/^([^\s]{{$iLength}}|.{1,{$iLength}}\s)/u";
00226         }
00227 
00228         $iStrLen = mb_strlen( $sString, $this->_sEncoding );
00229         $iWraps = floor( $iStrLen / $iLength );
00230 
00231         $i = $iWraps;
00232         $sReturn = '';
00233         $aMatches = array();
00234         while ( $i > 0 ) {
00235             $iWraps = floor( mb_strlen( $sString, $this->_sEncoding ) / $iLength );
00236 
00237             $i = $iWraps;
00238             if ( preg_match( $sRegexp, $sString, $aMatches ) ) {
00239                 $sStr = $aMatches[0];
00240                 $sReturn .= preg_replace( '/\s$/s', '', $sStr ) . $sBreak;
00241                 $sString = $this->substr( $sString , mb_strlen( $sStr, $this->_sEncoding ) );
00242             } else {
00243                 break;
00244             }
00245             $i--;
00246         }
00247         $sReturn = preg_replace( "/$sBreak$/", '', $sReturn );
00248         if ($sString) {
00249             $sReturn .= $sBreak.$sString;
00250         }
00251         return $sReturn;
00252     }
00253 
00266     public function recodeEntities( $sInput, $blToHtmlEntities = false, $aUmls = array(), $aUmlEntities = array() )
00267     {
00268         $aUmls = ( count( $aUmls ) > 0 ) ? array_merge( $this->_aUmls, $aUmls) : $this->_aUmls;
00269         $aUmlEntities = ( count( $aUmlEntities ) > 0 ) ? array_merge( $this->_aUmlEntities, $aUmlEntities) : $this->_aUmlEntities;
00270         return $blToHtmlEntities ? str_replace( $aUmls, $aUmlEntities, $sInput ) : str_replace( $aUmlEntities, $aUmls, $sInput );
00271     }
00272 
00280     public function hasSpecialChars( $sStr )
00281     {
00282         return $this->preg_match( "/(".implode( "|", $this->_aUmls  )."|(&amp;))/", $sStr );
00283     }
00284 
00294     public function cleanStr( $sStr, $sCleanChr = ' ' )
00295     {
00296         return $this->preg_replace( "/\"|\'|\.|\:|\!|\?|\n|\r|\t|\xc2\x95|\xc2\xa0|;/", $sCleanChr, $sStr );
00297     }
00298 }

Generated on Wed Apr 22 12:26:31 2009 for OXID eShop CE by  doxygen 1.5.5