PageRenderTime 55ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

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