3 public static function randomAlphaNumet($len){
5 $opt_str = "1234567890qwertyuiopasdfghjklzxcvbnmZXCVBNMASDFGHJKLQWERTYUIOP";
6 $options = str_split($opt_str);
7 $max = mb_strlen($opt_str) - 1;
8 for($char = 0 ; $char < $len ; $char++
){
9 $rand_string .= $options[rand(0, $max)];
12 return str_replace("/", "5", str_replace("=", "2", $rand_string));
16 class StandardFunctions
{
17 public static function getIniFile($path){
18 $path_file = fopen($path,"r");
19 $return_array = array();
20 while(!feof($path_file)){
21 $line = fgets($path_file);
22 $key = trim(substr($line,0,strpos($line, "=")));
24 $value = trim(substr($line, strpos($line, "=")+
1));
26 $return_array[$key] = $value;
32 public static function testBlock($val){
39 public static function recursiveEchoJson($json, $indents){
41 foreach($json as $key => $attribute){
42 if(is_array ($attribute)){
43 StandardFunctions
::makeIndents($indents);
46 StandardFunctions
::recursiveEchoJson($attribute, ++
$indents);
48 StandardFunctions
::makeIndents(--$indents);
52 StandardFunctions
::makeIndents($indents);
53 echo "$key = $attribute \n";
57 if($indents == 1) echo "<hr/>";
61 public static function makeIndents($indent_count){
62 for ($i = 0; $i < $indent_count ; $i++
){ echo "\t"; }
66 //https://stackoverflow.com/questions/5695145/how-to-read-and-write-to-an-ini-file-with-php
67 public static function write_php_ini($array, $file)
70 foreach($array as $key => $val)
75 foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ?
$sval : '"'.$sval.'"');
77 else $res[] = "$key = ".(is_numeric($val) ?
$val : '"'.$val.'"');
79 StandardFunctions
::safefilerewrite($file, implode("\r\n", $res));
82 public static function safefilerewrite($fileName, $dataToSave)
83 { if ($fp = fopen($fileName, 'w'))
85 $startTime = microtime(TRUE);
87 { $canWrite = flock($fp, LOCK_EX
);
88 // If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
89 if(!$canWrite) usleep(round(rand(0, 100)*1000));
90 } while ((!$canWrite)and((microtime(TRUE)-$startTime) < 5));
92 //file was locked so now we can store information
94 { fwrite($fp, $dataToSave);