00001 <?php
00011 class CorujaStringManipulation
00012 {
00013
00038 public static function strToBool( $strText )
00039 {
00040 if(!is_string($strText))
00041 {
00042 throw new InvalidArgumentException("Invalid argument [ ". var_export($strText) ." ]. It should be string");
00043 }
00044
00045 $strText = strtolower( $strText );
00046 if ( $strText === "false" || $strText === "" || $strText === "0" )
00047 {
00048 return( false );
00049 }
00050 return( true );
00051 }
00052
00079 public static function forceInt( $strText )
00080 {
00081 if(!is_string($strText))
00082 {
00083 throw new InvalidArgumentException("Invalid argument [ ". var_export($strText) ." ]. It should be string");
00084 }
00085
00086 $arrNum = Array( "0","1","2","3","4","5","6","7","8","9");
00087 $strResult = "";
00088 for( $i = 0; $i < strlen( $strText ); ++$i )
00089 {
00090 $charLetra = $strText[$i];
00091 if( $i == 0 && $charLetra == "-" )
00092 {
00093 $strResult .= $charLetra;
00094 }
00095 if( in_array($charLetra,$arrNum))
00096 {
00097 $strResult .= $charLetra;
00098 }
00099 }
00100 return $strResult += 0;
00101 }
00102
00125 public static function camelCaseToUnderlineCase( $strText )
00126 {
00127 if(!is_string($strText))
00128 {
00129 throw new InvalidArgumentException("Invalid argument [ ". var_export($strText) ." ]. It should be string");
00130 }
00131
00132 $arrFind = Array( "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" , "L" , "M" , "N" , "O" ,
00133 "P" , "Q" , "R" , "S" , "T" , "U" , "V" , "X" , "Z" , "W" , "Y" );
00134
00135 $arrReplace = Array( "_A" , "_B" , "_C" , "_D" , "_E" , "_F" , "_G" , "_H" , "_I" , "_J" , "_K" , "_L" , "_M" ,
00136 "_N" , "_O" , "_P" , "_Q" , "_R" , "_S" , "_T" , "_U" , "_V" , "_X" , "_Z" , "_W" , "_Y" );
00137
00138 if( strlen( $strText ) > 0 )
00139 {
00140 $strText[0] = strtolower($strText[0]);
00141 }
00142
00143 return strtoupper( str_replace( $arrFind , $arrReplace , $strText ) );
00144 }
00145
00146 public static function retab( $strText , $intDeeper )
00147 {
00148 $arrText = explode( "\n" , $strText );
00149 foreach( $arrText as $intKey => $strTextElement)
00150 {
00151 $arrText [ $intKey ] = trim( $strTextElement );
00152 }
00153 $strTab = "\n" .str_repeat( "\t" , $intDeeper );
00154 $strText = $strTab . implode( $strTab , $arrText ) . $strTab;
00155 return $strText;
00156 }
00157 }
00158 ?>