includes/functions.php
changeset 14 ce6053bb48d8
parent 1 fe660c52c48f
child 15 ad5986a53197
equal deleted inserted replaced
13:fdd6b9dd42c3 14:ce6053bb48d8
   861  * @return array
   861  * @return array
   862  */
   862  */
   863  
   863  
   864 function enano_str_split($text, $inc = 1)
   864 function enano_str_split($text, $inc = 1)
   865 {
   865 {
   866   if($inc < 1) return false;
   866   if($inc < 1) 
   867   if($inc >= strlen($text)) return Array($text);
   867   {
       
   868     return false;
       
   869   }
       
   870   if($inc >= strlen($text))
       
   871   {
       
   872     return Array($text);
       
   873   }
   868   $len = ceil(strlen($text) / $inc);
   874   $len = ceil(strlen($text) / $inc);
   869   $ret = Array();
   875   $ret = Array();
   870   for($i=0;$i<strlen($text);$i=$i+$inc)
   876   for ( $i = 0; $i < strlen($text); $i = $i + $inc )
   871   {
   877   {
   872     $ret[] = substr($text, $i, $inc);
   878     $ret[] = substr($text, $i, $inc);
   873   }
   879   }
   874   return $ret;
   880   return $ret;
   875 }
   881 }
   965   }
   971   }
   966   return $arr;
   972   return $arr;
   967 }
   973 }
   968 
   974 
   969 /**
   975 /**
       
   976  * Recursive function to remove all NUL bytes from a string
       
   977  * @param array
       
   978  * @return array
       
   979  */
       
   980  
       
   981 function strip_nul_chars($arr)
       
   982 {
       
   983   foreach($arr as $k => $xxxx_unused)
       
   984   {
       
   985     $val =& $arr[$k];
       
   986     if(is_string($val))
       
   987       $val = str_replace("\000", '', $val);
       
   988     elseif(is_array($val))
       
   989       $val = strip_nul_chars($val);
       
   990   }
       
   991   return $arr;
       
   992 }
       
   993 
       
   994 /**
   970  * If magic_quotes_gpc is on, calls stripslashes() on everything in $_GET/$_POST/$_COOKIE
   995  * If magic_quotes_gpc is on, calls stripslashes() on everything in $_GET/$_POST/$_COOKIE
   971  * @ignore - this doesn't work
   996  * @ignore - this doesn't work too well in my tests
   972  * @todo port version from the PHP manual
   997  * @todo port version from the PHP manual
   973  * @return void
   998  * @return void
   974  */
   999  */
   975 function strip_magic_quotes_gpc()
  1000 function strip_magic_quotes_gpc()
   976 {
  1001 {
   978   {
  1003   {
   979     $_POST   = stripslashes_recurse($_POST);
  1004     $_POST   = stripslashes_recurse($_POST);
   980     $_GET    = stripslashes_recurse($_GET);
  1005     $_GET    = stripslashes_recurse($_GET);
   981     $_COOKIE = stripslashes_recurse($_COOKIE);
  1006     $_COOKIE = stripslashes_recurse($_COOKIE);
   982   }
  1007   }
       
  1008   $_POST   = strip_nul_chars($_POST);
       
  1009   $_GET    = strip_nul_chars($_GET);
       
  1010   $_COOKIE = strip_nul_chars($_COOKIE);
   983 }
  1011 }
   984 
  1012 
   985 /**
  1013 /**
   986  * A very basic single-character compression algorithm for binary strings/bitfields
  1014  * A very basic single-character compression algorithm for binary strings/bitfields
   987  * @param string $bits the text to compress
  1015  * @param string $bits the text to compress