亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 語言 > PHP > 正文

PHP parse_ini_file函數的應用與擴展操作示例

2024-09-04 11:42:19
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了PHP parse_ini_file函數的應用與擴展操作,結合實例形式分析了php擴展parse_ini_file函數解析配置文件相關操作技巧,需要的朋友可以參考下

本文實例講述了PHP parse_ini_file函數的應用與擴展操作,分享給大家供大家參考,具體如下:

parse_ini_file($filename, $process_sections = false, $scanner_mode = INI_SCANNER_NORMAL)解析一個配置文件。

filename要解析的文件名;

process_sections設置為true時,得到一個多維數組,包括配置文件中每一節的名稱和設置,默認為false;

解析成功返回關聯數組,失敗返回false。列舉一下官網的例子,也引用了官網的擴展實例parse_ini_file_multi()。

下面是配置文件內容:

  1. [first_section] 
  2. one = 1 
  3. two = 2 
  4. name = test 
  5. [second_section] 
  6. path = '/tmp/test' 
  7. url = 'http://test.com/login.php' 
  8. [third_section] 
  9. php_version[] = '5.0' 
  10. php_version[] = '5.1' 
  11. php_version[] = '5.5' 
  12. [dictionary] 
  13. foo[debug] = true 
  14. foo[path] = /some/path 
  15. [fourth_section] 
  16. fold1.fold2.fold3 = 'a' 
  17. fold1.fold2.fold4 = 'b' 
  18. fold1.fold2.fold5 = 'b' 

下面是PHP文件內容:

  1. function parse_ini_file_multi($file$process_sections = false, $scanner_mode = INI_SCANNER_NORMAL){ 
  2.  $explode_str = '.'
  3.  $escape_char = "'"
  4.  $data = parse_ini_file($file$process_sections$scanner_mode); 
  5.  if (!$process_sections) { 
  6.   $data = array($data); 
  7.  } 
  8.  foreach ($data as $section_key => $section) { 
  9.   foreach($section as $key => $value){ 
  10.    if(strpos($key$explode_str)){ 
  11.     if(substr($key, 0, 1) !== $escape_char){ 
  12.      $sub_keys = explode($explode_str$key); 
  13.      $subs =& $data[$section_key]; 
  14.      echo "/r/n".'========='."/r/n"
  15.      print_r($subs); 
  16.      print_r($data); 
  17.      foreach($sub_keys as $sub_key){ 
  18.       if (!isset($subs[$sub_key])) { 
  19.        $subs[$sub_key] = []; 
  20.       } 
  21.       $subs =& $subs[$sub_key]; 
  22.       echo "/r/n".'++++++++'."/r/n"
  23.       print_r($subs); 
  24.       print_r($data); 
  25.      } 
  26.      $subs = $value
  27.      echo "/r/n".'----------'."/r/n"
  28.      print_r($subs); 
  29.      print_r($data); 
  30.      unset($data[$section_key][$key]); 
  31.     }else
  32.      $new_key = trim($key$escape_char); 
  33.      $data[$section_key][$new_key] = $value
  34.      unset($data[$section_key][$key]); 
  35.     } 
  36.    } 
  37.   } 
  38.  } 
  39.  if (!$process_sections) { 
  40.   $data = $data[0]; 
  41.  } 
  42.  return $data
  43. $arr = parse_ini_file('file.ini'); 
  44. print_r($arr); 
  45. echo "/r/n".'================='."/r/n"
  46. $arr = parse_ini_file_multi('file.ini',true); 
  47. echo "/r/n".'================='."/r/n"
  48. print_r($arr); 

運行結果:

  1. Array ( [one] => 1 [two] => 2 [name] => test [path] => /tmp/test [url] => http://test.com/login.php [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) [foo] => Array ( [debug] => 1 [path] => /some/path ) [fold1.fold2.fold3] => a [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b ) ================= ========= Array ( [fold1.fold2.fold3] => a [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold3] => a [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b ) ) ++++++++ Array ( ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold3] => a [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b [fold1] => Array ( ) ) ) ++++++++ Array ( ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold3] => a [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( ) ) ) ) ++++++++ Array ( ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold3] => a [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => Array ( ) ) ) ) ) ---------- aArray ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold3] => a [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a ) ) ) ) ========= Array ( [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a ) ) ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a ) ) ) ) ++++++++ Array ( [fold2] => Array ( [fold3] => a ) ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a ) ) ) ) ++++++++ Array ( [fold3] => a ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a ) ) ) ) ++++++++ Array ( ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a [fold4] => Array ( ) ) ) ) ) ---------- bArray ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold4] => b [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a [fold4] => b ) ) ) ) ========= Array ( [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a [fold4] => b ) ) ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a [fold4] => b ) ) ) ) ++++++++ Array ( [fold2] => Array ( [fold3] => a [fold4] => b ) ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a [fold4] => b ) ) ) ) ++++++++ Array ( [fold3] => a [fold4] => b ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a [fold4] => b ) ) ) ) ++++++++ Array ( ) Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a [fold4] => b [fold5] => Array ( ) ) ) ) ) ---------- bArray ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1.fold2.fold5] => b [fold1] => Array ( [fold2] => Array ( [fold3] => a [fold4] => b [fold5] => b ) ) ) ) ================= Array ( [first_section] => Array ( [one] => 1 [two] => 2 [name] => test ) [second_section] => Array ( [path] => /tmp/test [url] => http://test.com/login.php ) [third_section] => Array ( [php_version] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.5 ) ) [dictionary] => Array ( [foo] => Array ( [debug] => 1 [path] => /some/path ) ) [fourth_section] => Array ( [fold1] => Array ( [fold2] => Array ( [fold3] => a [fold4] => b [fold5] => b ) ) ) )

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
久久成人18免费网站| 国产精品都在这里| 亚洲精品在线不卡| 深夜成人在线观看| 国产精品三级网站| 久久精品国产2020观看福利| 国内揄拍国内精品少妇国语| 欧美精品久久久久久久| 欧美放荡办公室videos4k| 欧美成人激情图片网| 久久精品亚洲国产| 亚洲欧美日韩精品久久| 亚洲第一区中文99精品| 久久久久久综合网天天| 欧美综合国产精品久久丁香| 国产成人精品a视频一区www| 伊人青青综合网站| 亚洲人成电影网站色| 91九色国产在线| 久久久av电影| 亚洲jizzjizz日本少妇| 日韩欧美国产骚| 秋霞av国产精品一区| 最近2019年好看中文字幕视频| 亚洲成人精品在线| 91精品国产高清久久久久久久久| 国产精品福利观看| 57pao成人国产永久免费| 国产精品一区二区久久国产| 51ⅴ精品国产91久久久久久| 欧美日韩人人澡狠狠躁视频| 久久精品国产免费观看| 亚洲一区二区在线播放| 欧美大片欧美激情性色a∨久久| 亚洲专区在线视频| 国内成人精品一区| 国产视频久久久| 国产精品2018| 粗暴蹂躏中文一区二区三区| 日韩成人av在线播放| 91精品视频在线| 亚洲精品第一页| 国产精品丝袜一区二区三区| 狠狠色狠狠色综合日日小说| 性欧美xxxx视频在线观看| 91九色视频导航| 日韩av色综合| 国产91色在线|免| 国产不卡一区二区在线播放| 欧美激情精品久久久| 亚洲护士老师的毛茸茸最新章节| 亚洲第一区第一页| 欧洲亚洲在线视频| 亚洲aⅴ男人的天堂在线观看| 欧美日韩不卡合集视频| 一本色道久久88精品综合| 国产成人久久精品| 久久久国产视频91| www.欧美免费| 精品国产一区二区三区久久久狼| 97精品在线观看| 98精品在线视频| 国产精品啪视频| 欧美不卡视频一区发布| 国产欧美日韩中文| 欧洲精品在线视频| 国产欧美 在线欧美| 国产精品久久久久久av下载红粉| 国产精品久久久久久久久久久久| 国产精品69精品一区二区三区| 亚洲欧美激情另类校园| 欧美丰满少妇xxxxx| 欧美精品videos性欧美| 欧美精品video| 日产日韩在线亚洲欧美| 富二代精品短视频| 亚洲高清在线观看| 精品国产欧美一区二区三区成人| 91国产精品视频在线| 国产精品福利网站| 日韩av手机在线| 亚洲国产精品高清久久久| 国产视频精品自拍| 久久综合色88| 亚洲男人天堂网| 欧美日韩亚洲精品一区二区三区| 国产综合福利在线| 国产日韩欧美在线看| 欧美极品美女视频网站在线观看免费| 国产香蕉精品视频一区二区三区| 国产成人a亚洲精品| 亚洲男人天天操| 亚洲二区中文字幕| 久久国产精品首页| 日韩av在线导航| 成人黄色av免费在线观看| 色诱女教师一区二区三区| 97精品国产91久久久久久| 日韩一区视频在线| 国产日韩欧美中文| 国产精品www| 欧美疯狂做受xxxx高潮| 日韩网站免费观看高清| 欧美激情视频播放| 一区二区欧美亚洲| 欧美一级片在线播放| 日韩美女免费视频| 日韩av在线网页| 久久天天躁狠狠躁夜夜av| 久久久国产视频| 欧美综合在线观看| 欧美午夜电影在线| 国产精品自产拍在线观| 日本国产精品视频| 亚洲国产女人aaa毛片在线| 久久综合久中文字幕青草| 亚洲成人xxx| 日本成人在线视频网址| 日韩国产高清视频在线| 亚洲欧美日韩直播| 欧美日韩国产综合视频在线观看中文| 中文字幕日韩在线观看| 久久视频在线看| 欧美高清在线视频观看不卡| 日韩国产精品亚洲а∨天堂免| 欧美成在线视频| 国内精品国产三级国产在线专| 91理论片午午论夜理片久久| 最好看的2019的中文字幕视频| 97免费视频在线| 欧亚精品中文字幕| 国产99久久久欧美黑人| 欧美一级免费看| 国产自摸综合网| 亚洲成人a级网| 午夜精品久久久久久久久久久久| 久久精品最新地址| 美日韩精品免费观看视频| 久久久久久久久久国产| 亚洲第一精品久久忘忧草社区| 久久伊人精品一区二区三区| 亚洲视频在线看| 久久亚洲精品国产亚洲老地址| 欧美劲爆第一页| 曰本色欧美视频在线| 国产98色在线| 久久久久久12| 亚洲黄色www网站| 日韩欧美国产网站| 成人有码在线播放| 欧美日韩一区免费| 亚洲精品小视频| 日本高清久久天堂| 国产精品av免费在线观看| 一本色道久久综合亚洲精品小说| 91大神福利视频在线| 最新亚洲国产精品| 日韩av一卡二卡| 国产精品久久久久免费a∨大胸| 国产精品福利在线观看| 国产专区精品视频| 日本一区二区三区在线播放| 国产精品一区二区在线| 亚洲一区二区三区香蕉|