PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/general_functions/parse_ini_string_001.php

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