Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. $filename = "test.ini";
  2. $handle = @fopen($filename, "r");
  3. $result = [];
  4. if ($handle) {
  5.     while (($buffer = fgets($handle, 4096)) !== false) { //строка до 4КБ
  6.         list($inikeys, $value) = explode('=', $buffer);
  7.         $inikeys = explode('.', $inikeys);
  8.         $current = &$result;
  9.         foreach ($inikeys as $key => $inikey){
  10.             if(!array_key_exists( $inikey, $current ) && $key + 1 < count($inikeys)){
  11.                 $current[$inikey] = [];
  12.             }
  13.             $current = &$current[$inikey];
  14.         }
  15.         $current = str_replace("\n", '', str_replace("\r", '', $value));
  16.         unset($current);
  17.     }
  18.     fclose($handle);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement