src/IniReader.php
public function readComments($filename)
    {
        $ini = $this->getContentOfIniFile($filename);
        $ini = $this->splitIniContentIntoLines($ini);

        $descriptions = array();

        $section = '';
        $lastComment = '';

        foreach ($ini as $line) {
            $line = trim($line);

            if (strpos($line, '[') === 0) {
                $tmp = explode(']', $line);
                $section = trim(substr($tmp[0], 1));
                $descriptions[$section] = array();
                $lastComment = '';
                continue;
            }

            if (!preg_match('/^[a-zA-Z0-9[]/', $line)) {
                if (strpos($line, ';') === 0) {
                    $line = trim(substr($line, 1));
                }
                // comment
                $lastComment .= $line . "\n";
                continue;
            }

            list($key, $value) = explode('=', $line, 2);

            $key = trim($key);
            if (strpos($key, '[]') === strlen($key) - 2) {
                $key = substr($key, 0, -2);
            }

            if (empty($descriptions[$section][$key])) {
                $descriptions[$section][$key] = $lastComment;
            }

            $lastComment = '';
        }

        return $descriptions;
    }
public function readComments($filename)
    {
        $ini = $this->getContentOfIniFile($filename);
        $ini = $this->splitIniContentIntoLines($ini);

        $descriptions = array();

        $section = '';
        $lastComment = '';

        foreach ($ini as $line) {
            $line = trim($line);

            if (strpos($line, '[') === 0) {
                $tmp = explode(']', $line);
                $section = trim(substr($tmp[0], 1));
                $descriptions[$section] = array();
                $lastComment = '';
                continue;
            }

            if (!preg_match('/^[a-zA-Z0-9[]/', $line)) {
                if (strpos($line, ';') === 0) {
                    $line = trim(substr($line, 1));
                }
                // comment
                $lastComment .= $line . "\n";
                continue;
            }

            list($key, $value) = explode('=', $line, 2);

            $key = trim($key);
            if (strpos($key, '[]') === strlen($key) - 2) {
                $key = substr($key, 0, -2);
            }

            if (empty($descriptions[$section][$key])) {
                $descriptions[$section][$key] = $lastComment;
            }

            $lastComment = '';
        }

        return $descriptions;
    }
public function readComments ( $ filename ) { $ ini = $ this -> getContentOfIniFile ( $ filename ) ; $ ini = $ this -> splitIniContentIntoLines ( $ ini ) ; $ descriptions = array ( ) ; $ section = '' ; $ lastComment = '' ; foreach ( $ ini as $ line ) { $ line = trim ( $ line ) ; if ( strpos ( $ line , '[' ) === 0 ) { $ tmp = explode ( ']' , $ line ) ; $ section = trim ( substr ( $ tmp [ 0 ] , 1 ) ) ; $ descriptions [ $ section ] = array ( ) ; $ lastComment = '' ; continue ; } if ( ! preg_match ( '/^[a-zA-Z0-9[]/' , $ line ) ) { if ( strpos ( $ line , ';' ) === 0 ) { $ line = trim ( substr ( $ line , 1 ) ) ; } // comment $ lastComment .= $ line . "\n" ; continue ; } list ( $ key , $ value ) = explode ( '=' , $ line , 2 ) ; $ key = trim ( $ key ) ; if ( strpos ( $ key , '[]' ) === strlen ( $ key ) - 2 ) { $ key = substr ( $ key , 0 , - 2 ) ; } if ( empty ( $ descriptions [ $ section ] [ $ key ] ) ) { $ descriptions [ $ section ] [ $ key ] = $ lastComment ; } $ lastComment = '' ; } return $ descriptions ; }
Reads ini comments for each key.

The array returned is multidimensional, indexed by section names:

```
array(
'Section 1' => array(
'key1' => 'comment 1',
'key2' => 'comment 2',
),
'Section 2' => array(
'key3' => 'comment 3',
)
);
```

@param string $filename The path to a file.
@throws IniReadingException
@return array
Reads ini comments for each key .