downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

pathinfo> <parse_ini_file
[edit] Last updated: Fri, 23 Mar 2012

view this page in

parse_ini_string

(PHP 5 >= 5.3.0)

parse_ini_stringBir yapılandırma dizgesini çözümler

Açıklama

array parse_ini_string ( string $ini [, bool $bölümleri_işle = false [, int $tarama_kipi = INI_SCANNER_NORMAL ]] )

parse_ini_string() işlevi ini dizgesi içindeki ayarları bir ilişkisel dizi içinde döndürür.

ini dizgesinin yapısı php.ini dosyasının yapısıyla aynı olmalıdır.

Değiştirgeler

ini

Çözümlenecek ini dosyası içeriği.

bölümleri_işle

Bu değiştirgeye TRUE atanırsa bölüm isimlerini ve içerdikleri ayarları içeren çok boyutlu bir dizi döner. Değiştirgenin öntanımlı değeri FALSE'tır.

tarama_kipi

Değeri INI_SCANNER_NORMAL (öntanımlıdır) veya INI_SCANNER_RAW olabilir. Eğer INI_SCANNER_RAW belirtilirse seçenek değerleri çözümlenmez.

Dönen Değerler

Başarısızlık durumunda FALSE aksi takdirde ayarları bir ilişkisel dizi içinde döndürür.

Notlar

Bilginize: INI dosyalarında anahtar olarak kullanılmaması gereken bazı özel sözcükler vardır. null, yes, no, true, false, on, off, none bunlardan bazılarıdır. null, no ve false "" ile sonuçlanırken, yes ve true "1" ile sonuçlanır. {}|&~![()^" karakterleri hiçbir yerde anahtar veya değer olarak kullanılmamalıdır.

Ayrıca Bakınız



pathinfo> <parse_ini_file
[edit] Last updated: Fri, 23 Mar 2012
 
add a note add a note User Contributed Notes parse_ini_string
Safak Ozpinar (safakozpinar at gmail dot com) 25-Oct-2010 02:20
Function parse_ini_file doesn't parse a remote ini file if allow_url_include is off. But if allow_url_fopen is on, you can use parse_ini_string to parse a remote ini file after read its contents.

<?php
/**
 * Assume that; allow_url_include=0 and allow_url_fopen=1
 * (default values in php.ini)
 */
$iniUrl = 'http://example.com/remote/config.ini';

/**
 * Warning: parse_ini_file(): http:// wrapper is disabled in the server configuration by allow_url_include=0
 */
$config = parse_ini_file($iniUrl);

/**
 * works fine
 */
$config = parse_ini_string(file_get_contents($iniUrl));
?>
boukeversteegh at gmail dot com 28-Apr-2010 10:05
<?php
# Define parse_ini_string if it doesn't exist.
# Does accept lines starting with ; as comments
# Does not accept comments after values
if( !function_exists('parse_ini_string') ){
   
    function
parse_ini_string( $string ) {
       
$array = Array();

       
$lines = explode("\n", $string );
       
        foreach(
$lines as $line ) {
           
$statement = preg_match(
"/^(?!;)(?P<key>[\w+\.\-]+?)\s*=\s*(?P<value>.+?)\s*$/", $line, $match );

            if(
$statement ) {
               
$key    = $match[ 'key' ];
               
$value    = $match[ 'value' ];
               
               
# Remove quote
               
if( preg_match( "/^\".*\"$/", $value ) || preg_match( "/^'.*'$/", $value ) ) {
                   
$value = mb_substr( $value, 1, mb_strlen( $value ) - 2 );
                }
               
               
$array[ $key ] = $value;
            }
        }
        return
$array;
    }
}
?>
alexandre at nospam dot imaginacom dot com 21-Oct-2009 12:24
If your server has yet not been updated to PHP 5.2 (like mine), the following function can help you without having to use temporary paths.

I tried to make it the more similar possible to the PHP's behaviour, including dealing with errors or exceptions.

<?php
if(!function_exists('parse_ini_string')){
    function
parse_ini_string($str, $ProcessSections=false){
       
$lines  = explode("\n", $str);
       
$return = Array();
       
$inSect = false;
        foreach(
$lines as $line){
           
$line = trim($line);
            if(!
$line || $line[0] == "#" || $line[0] == ";")
                continue;
            if(
$line[0] == "[" && $endIdx = strpos($line, "]")){
               
$inSect = substr($line, 1, $endIdx-1);
                continue;
            }
            if(!
strpos($line, '=')) // (We don't use "=== false" because value 0 is not valid as well)
               
continue;
           
           
$tmp = explode("=", $line, 2);
            if(
$ProcessSections && $inSect)
               
$return[$inSect][trim($tmp[0])] = ltrim($tmp[1]);
            else
               
$return[trim($tmp[0])] = ltrim($tmp[1]);
        }
        return
$return;
    }
}
?>
aldo at mschat dot net 01-Aug-2009 03:28
If you want to use something like this on a PHP version below that of PHP 5.3, you can emulate it roughly by doing something like this:

<?php
if(!function_exists('parse_ini_string'))
{
  function
parse_ini_string($ini, $process_sections = false, $scanner_mode = null)
  {
   
# Generate a temporary file.
   
$tempname = tempnam('/tmp', 'ini');
   
$fp = fopen($tempname, 'w');
   
fwrite($fp, $ini);
   
$ini = parse_ini_file($tempname, !empty($process_sections));
   
fclose($fp);
    @
unlink($tempname);
    return
$ini;
  }
}
?>

May not be the most efficient way (I suppose you could do some regex stuff instead...) but it certainly works!

 
show source | credits | stats | sitemap | contact | advertising | mirror sites