PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/file/parse_ini_file.php

http://github.com/facebook/hiphop-php
PHP | 212 lines | 199 code | 9 blank | 4 comment | 0 complexity | 46e42702267ff4b46a59780795348154 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype: array parse_ini_file(string $filename [,bool $process_sections]);
  3. Description: parse_ini_file() loads in the ini file specified in filename,
  4. and returns the settings in it in an associative array.
  5. */
  6. const BIRD = 'Humming bird';
  7. <<__EntryPoint>> function main(): void {
  8. $parse_string = <<<EOD
  9. ; Comment starts with semi-colon(;)
  10. ; Section starts with [<section name>]
  11. ; start of ini file
  12. [Constans]
  13. one = 1
  14. five = 5
  15. animal = BIRD
  16. Language = PHP
  17. PHP_CONSTANT = 1.2345678
  18. 10 = Ten
  19. HELLO = HELLO
  20. [date]
  21. date =
  22. time =
  23. [paths]
  24. path = /usr/local/bin
  25. URL = http://www.php.net
  26. [Decimal]
  27. Decimal_value1 = 100
  28. Decimal_value2 = -100
  29. Decimal_value3 = -2147483647
  30. Decimal_value4 = 2147483647
  31. Decimal_value5 = -2147483648
  32. Decimal_value6 = 2147483648
  33. [Octal]
  34. Octal_value = 0100
  35. [Hex]
  36. Hex_value1 = 0x101
  37. Hex_Value2 = 0x102
  38. Hex_Value2 = 0x103
  39. [Non-alphanumerics_as_values]
  40. ;Non-alpha numeric chars without quotes
  41. Non_alpha1 = ;
  42. Non_alpha2 = +
  43. Non_alpha3 = *
  44. Non_alpha4 = %
  45. Non_alpha5 = <>
  46. Non_alpha6 = @
  47. Non_alpha7 = #
  48. Non_alpha8 = -
  49. Non_alpha9 = :
  50. Non_alpha10 = ?
  51. Non_alpha11 = /
  52. Non_alpha12 = \
  53. ;These chars have a special meaning when used in the value,
  54. ; hence parser throws an error
  55. ;Non_alpha13 = &
  56. ;Non_alpha14 = ^
  57. ;Non_alpha15 = {}
  58. ;Non_alpha16 = |
  59. ;Non_alpha17 = ~
  60. ;Non_alpha18 = !
  61. ;Non_alpha19 = $
  62. ;Non_alpha20 = ()
  63. Non_alpha1_quotes = ";"
  64. Non_alpha2_quotes = "+"
  65. Non_alpha3_quotes = "*"
  66. Non_alpha4_quotes = "%"
  67. Non_alpha5_quotes = "<>"
  68. Non_alpha6_quotes = "@"
  69. Non_alpha7_quotes = "#"
  70. Non_alpha8_quotes = "^"
  71. Non_alpha9_quotes = "-"
  72. Non_alpha10_quotes = "="
  73. Non_alpha11_quotes = ":"
  74. Non_alpha12_quotes = "?"
  75. Non_alpha13_quotes = "/"
  76. ;Non_alpha14_quotes = "\"
  77. Non_alpha15_quotes = "&"
  78. Non_alpha16_quotes = "{}"
  79. Non_alpha17_quotes = "|"
  80. Non_alpha18_quotes = "~"
  81. Non_alpha19_quotes = "!"
  82. ;Non_alpha20_quotes = "$"
  83. Non_alpha21_quotes = "()"
  84. [Non-alpha numerics in strings]
  85. ;expected error, as the non-alphanumeric chars not enclosed in double quotes("")
  86. Non_alpha_string1 = Hello@world
  87. ;Non_alpha_string2 = Hello!world
  88. ;Non_alpha_string3 = Hello#world
  89. ;Non_alpha_string4 = Hello%world
  90. ;Non_alpha_string5 = Hello&world
  91. ;Non_alpha_string6 = Hello*world
  92. ;Non_alpha_string7 = Hello+world
  93. ;Non_alpha_string8 = Hello-world
  94. ;Non_alpha_string9 = Hello'world
  95. ;Non_alpha_string10 = Hello:world
  96. ;Non_alpha_string11 = Hello;world
  97. ;Non_alpha_string12 = Hello<world
  98. ;Non_alpha_string13 = Hello>world
  99. ;Non_alpha_string14 = Hello>world
  100. ;Non_alpha_string15 = Hello?world
  101. ;Non_alpha_string16 = Hello\world
  102. ;Non_alpha_string17 = Hello^world
  103. ;Non_alpha_string18 = Hello_world
  104. ;Non_alpha_string19 = Hello|world
  105. ;Non_alpha_string20 = Hello~world
  106. ;Non_alpha_string21 = Hello`world
  107. ;Non_alpha_string22 = Hello(world)
  108. [Non-alpha numerics in strings -with quotes]
  109. Non_alpha_string1_quotes = "Hello@world"
  110. Non_alpha_string2_quotes = "Hello!world"
  111. Non_alpha_string3_quotes = "Hello#world"
  112. Non_alpha_string4_quotes = "Hello&world"
  113. Non_alpha_string5_quotes = "Hello*world"
  114. Non_alpha_string6_quotes = "Hello+world"
  115. Non_alpha_string7_quotes = "Hello-world"
  116. Non_alpha_string8_quotes = "Hello'world"
  117. Non_alpha_string9_quotes = "Hello:world"
  118. Non_alpha_string10_quotes = "Hello;world"
  119. Non_alpha_string11_quotes = "Hello<world"
  120. Non_alpha_string12_quotes = "Hello>world"
  121. Non_alpha_string13_quotes = "Hello>world"
  122. Non_alpha_string14_quotes = "Hello?world"
  123. Non_alpha_string15_quotes = "Hello\world"
  124. Non_alpha_string16_quotes = "Hello^world"
  125. Non_alpha_string17_quotes = "Hello_world"
  126. Non_alpha_string18_quotes = "Hello|world"
  127. Non_alpha_string19_quotes = "Hello~world"
  128. Non_alpha_string20_quotes = "Hello`world"
  129. Non_alpha_string21_quotes = "Hello(world)"
  130. [Newlines_in_Values]
  131. String1 = "Hello, world\nGood Morning"
  132. String2 = "\nHello, world
  133. Good Morning\n"
  134. String3 = 'Hello, world\tGood Morning'
  135. String4 = "\n"
  136. String5 = "\n\n"
  137. String6 = Hello, world\tGood Morning
  138. [ReservedKeys_as_Values]
  139. Key1 = YES
  140. Key2 = Yes
  141. Key3 = yEs
  142. Key4 = NO
  143. Key5 = No
  144. Key6 = nO
  145. Key7 = TRUE
  146. Key8 = True
  147. Key9 = tRUE
  148. Key10 = true
  149. Key11 = FALSE
  150. Key12 = False
  151. Key13 = false
  152. Key14 = fAlSE
  153. Key15 = NULL
  154. Key16 = Null
  155. Key17 = nuLL
  156. Key18 = null
  157. [ReservedKeys_as_Keys]
  158. ; Expected:error, reserved key words must not be used as keys for ini file
  159. ;YES = 1
  160. ;Yes = 2
  161. ;yEs = 1.2
  162. ;YES = YES
  163. ;NO = ""
  164. ;No = "string"
  165. ;nO = "\0"
  166. ;TRUE = 1.1
  167. ;True = 1
  168. ;tRUE = 5
  169. ;true = TRUE
  170. ;FALSE = FALSE
  171. ;False = ""
  172. ;false = "hello"
  173. ;fAlSE = ""
  174. ;NULL = ""
  175. ;Null = 0
  176. ;nuLL = "\0"
  177. ;null = NULL
  178. ; end of ini file
  179. EOD;
  180. /* creating parse.ini file */
  181. $file_handle = fopen(__DIR__."/parse_ini_file.ini", "w");
  182. fwrite($file_handle, $parse_string);
  183. fclose($file_handle);
  184. echo "*** Test parse_ini_file() function: with various keys and values given in parse.ini file ***\n";
  185. echo "-- ini file without process_sections optional arg --\n";
  186. $ini_array = parse_ini_file(__DIR__."/parse_ini_file.ini");
  187. print_r($ini_array);
  188. echo "\n-- ini file with process_sections as TRUE --\n";
  189. $ini_array = parse_ini_file(__DIR__."/parse_ini_file.ini", TRUE);
  190. print_r($ini_array);
  191. echo "*** Done **\n";
  192. error_reporting(0);
  193. unlink(__DIR__."/parse_ini_file.ini");
  194. }