$value){ $text = str_replace("_tK_{$key}_", $value, $text); } file_put_contents($destFilePath, $text); return true; } /** * '비교적' 안전한 int 변환 * null -> null * int -> int * float -> int * numeric(int, float) 포함 -> int * 기타 -> 예외처리 * * @return int|null */ function toInt($val, $force=false){ if($val === null){ return null; } if(is_int($val)){ return $val; } if(is_numeric($val)){ return intval($val);// } if(strtolower($val) === 'null'){ return null; } if($force){ return intval($val); } throw new InvalidArgumentException('올바르지 않은 타입형 :'.$val); } /** * Generate a random string, using a cryptographically secure * pseudorandom number generator (random_int) * * For PHP 7, random_int is a PHP core function * For PHP 5.x, depends on https://github.com/paragonie/random_compat * * @param int $length How many characters do we want? * @param string $keyspace A string of all possible characters * to select from * @return string */ function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { $str = ''; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $str .= $keyspace[random_int(0, $max)]; } return $str; }