fgetss_variation2.phpt 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. --TEST--
  2. Test fgetss() function : usage variations - read modes
  3. --FILE--
  4. <?php
  5. /*
  6. Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
  7. Description: Gets line from file pointer and strip HTML tags
  8. */
  9. // include the common file related test functions
  10. include ("file.inc");
  11. /*Test fgetss() with all read modes , reading line by line with allowable tags: <test>, <html>, <?> */
  12. echo "*** Testing fgetss() : usage variations ***\n";
  13. /* string with html and php tags */
  14. $string_with_tags = <<<EOT
  15. <test>Testing fgetss() functions</test>
  16. <?php echo "this string is within php tag"; ?> {;}<{> this
  17. is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
  18. <html> html </html> <?php echo "php"; ?>
  19. this line is without any html and php tags
  20. this is a line with more than eighty character,want to check line splitting correctly after 80 characters
  21. this is the text containing \r character
  22. this text contains some html tags <body> body </body> <br> br </br>
  23. this is the line with \n character.
  24. EOT;
  25. $filename = dirname(__FILE__)."/fgetss_variation2.tmp";
  26. /* try reading the file opened in different modes of reading */
  27. $file_modes = array("r","rb", "rt","r+", "r+b", "r+t");
  28. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  29. echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
  30. /* create an empty file and write the strings with tags */
  31. create_file ($filename); //create an empty file
  32. file_put_contents($filename, $string_with_tags);
  33. $file_handle = fopen($filename, $file_modes[$mode_counter]);
  34. if(!$file_handle) {
  35. echo "Error: failed to open file $filename!\n";
  36. exit();
  37. }
  38. // rewind the file pointer to beginning of the file
  39. var_dump( filesize($filename) );
  40. var_dump( rewind($file_handle) );
  41. var_dump( ftell($file_handle) );
  42. var_dump( feof($file_handle) );
  43. /* rewind the file and read the file line by line with allowable tags */
  44. echo "-- Reading line by line with allowable tags: <test>, <html>, <?> --\n";
  45. rewind($file_handle);
  46. $line = 1;
  47. while( !feof($file_handle) ) {
  48. echo "-- Line $line --\n"; $line++;
  49. var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") );
  50. var_dump( ftell($file_handle) ); // check the file pointer position
  51. var_dump( feof($file_handle) ); // check if eof reached
  52. }
  53. // close the file
  54. fclose($file_handle);
  55. // delete the file
  56. delete_file($filename);
  57. } // end of for - mode_counter
  58. echo "Done\n";
  59. ?>
  60. --EXPECTF--
  61. *** Testing fgetss() : usage variations ***
  62. -- Testing fgetss() with file opened using r mode --
  63. int(486)
  64. bool(true)
  65. int(0)
  66. bool(false)
  67. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  68. -- Line 1 --
  69. string(40) "<test>Testing fgetss() functions</test>
  70. "
  71. int(40)
  72. bool(false)
  73. -- Line 2 --
  74. string(10) " {;} this
  75. "
  76. int(99)
  77. bool(false)
  78. -- Line 3 --
  79. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  80. "
  81. int(152)
  82. bool(false)
  83. -- Line 4 --
  84. string(21) "<html> html </html>
  85. "
  86. int(193)
  87. bool(false)
  88. -- Line 5 --
  89. string(43) "this line is without any html and php tags
  90. "
  91. int(236)
  92. bool(false)
  93. -- Line 6 --
  94. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  95. int(315)
  96. bool(false)
  97. -- Line 7 --
  98. string(27) "rectly after 80 characters
  99. "
  100. int(342)
  101. bool(false)
  102. -- Line 8 --
  103. string(41) "this is the text containing character
  104. "
  105. int(383)
  106. bool(false)
  107. -- Line 9 --
  108. string(46) "this text contains some html tags body br
  109. "
  110. int(451)
  111. bool(false)
  112. -- Line 10 --
  113. string(23) "this is the line with
  114. "
  115. int(474)
  116. bool(false)
  117. -- Line 11 --
  118. string(12) " character. "
  119. int(486)
  120. bool(true)
  121. -- Testing fgetss() with file opened using rb mode --
  122. int(486)
  123. bool(true)
  124. int(0)
  125. bool(false)
  126. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  127. -- Line 1 --
  128. string(40) "<test>Testing fgetss() functions</test>
  129. "
  130. int(40)
  131. bool(false)
  132. -- Line 2 --
  133. string(10) " {;} this
  134. "
  135. int(99)
  136. bool(false)
  137. -- Line 3 --
  138. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  139. "
  140. int(152)
  141. bool(false)
  142. -- Line 4 --
  143. string(21) "<html> html </html>
  144. "
  145. int(193)
  146. bool(false)
  147. -- Line 5 --
  148. string(43) "this line is without any html and php tags
  149. "
  150. int(236)
  151. bool(false)
  152. -- Line 6 --
  153. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  154. int(315)
  155. bool(false)
  156. -- Line 7 --
  157. string(27) "rectly after 80 characters
  158. "
  159. int(342)
  160. bool(false)
  161. -- Line 8 --
  162. string(41) "this is the text containing character
  163. "
  164. int(383)
  165. bool(false)
  166. -- Line 9 --
  167. string(46) "this text contains some html tags body br
  168. "
  169. int(451)
  170. bool(false)
  171. -- Line 10 --
  172. string(23) "this is the line with
  173. "
  174. int(474)
  175. bool(false)
  176. -- Line 11 --
  177. string(12) " character. "
  178. int(486)
  179. bool(true)
  180. -- Testing fgetss() with file opened using rt mode --
  181. int(486)
  182. bool(true)
  183. int(0)
  184. bool(false)
  185. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  186. -- Line 1 --
  187. string(40) "<test>Testing fgetss() functions</test>
  188. "
  189. int(40)
  190. bool(false)
  191. -- Line 2 --
  192. string(10) " {;} this
  193. "
  194. int(99)
  195. bool(false)
  196. -- Line 3 --
  197. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  198. "
  199. int(152)
  200. bool(false)
  201. -- Line 4 --
  202. string(21) "<html> html </html>
  203. "
  204. int(193)
  205. bool(false)
  206. -- Line 5 --
  207. string(43) "this line is without any html and php tags
  208. "
  209. int(236)
  210. bool(false)
  211. -- Line 6 --
  212. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  213. int(315)
  214. bool(false)
  215. -- Line 7 --
  216. string(27) "rectly after 80 characters
  217. "
  218. int(342)
  219. bool(false)
  220. -- Line 8 --
  221. string(41) "this is the text containing character
  222. "
  223. int(383)
  224. bool(false)
  225. -- Line 9 --
  226. string(46) "this text contains some html tags body br
  227. "
  228. int(451)
  229. bool(false)
  230. -- Line 10 --
  231. string(23) "this is the line with
  232. "
  233. int(474)
  234. bool(false)
  235. -- Line 11 --
  236. string(12) " character. "
  237. int(486)
  238. bool(true)
  239. -- Testing fgetss() with file opened using r+ mode --
  240. int(486)
  241. bool(true)
  242. int(0)
  243. bool(false)
  244. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  245. -- Line 1 --
  246. string(40) "<test>Testing fgetss() functions</test>
  247. "
  248. int(40)
  249. bool(false)
  250. -- Line 2 --
  251. string(10) " {;} this
  252. "
  253. int(99)
  254. bool(false)
  255. -- Line 3 --
  256. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  257. "
  258. int(152)
  259. bool(false)
  260. -- Line 4 --
  261. string(21) "<html> html </html>
  262. "
  263. int(193)
  264. bool(false)
  265. -- Line 5 --
  266. string(43) "this line is without any html and php tags
  267. "
  268. int(236)
  269. bool(false)
  270. -- Line 6 --
  271. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  272. int(315)
  273. bool(false)
  274. -- Line 7 --
  275. string(27) "rectly after 80 characters
  276. "
  277. int(342)
  278. bool(false)
  279. -- Line 8 --
  280. string(41) "this is the text containing character
  281. "
  282. int(383)
  283. bool(false)
  284. -- Line 9 --
  285. string(46) "this text contains some html tags body br
  286. "
  287. int(451)
  288. bool(false)
  289. -- Line 10 --
  290. string(23) "this is the line with
  291. "
  292. int(474)
  293. bool(false)
  294. -- Line 11 --
  295. string(12) " character. "
  296. int(486)
  297. bool(true)
  298. -- Testing fgetss() with file opened using r+b mode --
  299. int(486)
  300. bool(true)
  301. int(0)
  302. bool(false)
  303. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  304. -- Line 1 --
  305. string(40) "<test>Testing fgetss() functions</test>
  306. "
  307. int(40)
  308. bool(false)
  309. -- Line 2 --
  310. string(10) " {;} this
  311. "
  312. int(99)
  313. bool(false)
  314. -- Line 3 --
  315. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  316. "
  317. int(152)
  318. bool(false)
  319. -- Line 4 --
  320. string(21) "<html> html </html>
  321. "
  322. int(193)
  323. bool(false)
  324. -- Line 5 --
  325. string(43) "this line is without any html and php tags
  326. "
  327. int(236)
  328. bool(false)
  329. -- Line 6 --
  330. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  331. int(315)
  332. bool(false)
  333. -- Line 7 --
  334. string(27) "rectly after 80 characters
  335. "
  336. int(342)
  337. bool(false)
  338. -- Line 8 --
  339. string(41) "this is the text containing character
  340. "
  341. int(383)
  342. bool(false)
  343. -- Line 9 --
  344. string(46) "this text contains some html tags body br
  345. "
  346. int(451)
  347. bool(false)
  348. -- Line 10 --
  349. string(23) "this is the line with
  350. "
  351. int(474)
  352. bool(false)
  353. -- Line 11 --
  354. string(12) " character. "
  355. int(486)
  356. bool(true)
  357. -- Testing fgetss() with file opened using r+t mode --
  358. int(486)
  359. bool(true)
  360. int(0)
  361. bool(false)
  362. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  363. -- Line 1 --
  364. string(40) "<test>Testing fgetss() functions</test>
  365. "
  366. int(40)
  367. bool(false)
  368. -- Line 2 --
  369. string(10) " {;} this
  370. "
  371. int(99)
  372. bool(false)
  373. -- Line 3 --
  374. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  375. "
  376. int(152)
  377. bool(false)
  378. -- Line 4 --
  379. string(21) "<html> html </html>
  380. "
  381. int(193)
  382. bool(false)
  383. -- Line 5 --
  384. string(43) "this line is without any html and php tags
  385. "
  386. int(236)
  387. bool(false)
  388. -- Line 6 --
  389. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  390. int(315)
  391. bool(false)
  392. -- Line 7 --
  393. string(27) "rectly after 80 characters
  394. "
  395. int(342)
  396. bool(false)
  397. -- Line 8 --
  398. string(41) "this is the text containing character
  399. "
  400. int(383)
  401. bool(false)
  402. -- Line 9 --
  403. string(46) "this text contains some html tags body br
  404. "
  405. int(451)
  406. bool(false)
  407. -- Line 10 --
  408. string(23) "this is the line with
  409. "
  410. int(474)
  411. bool(false)
  412. -- Line 11 --
  413. string(12) " character. "
  414. int(486)
  415. bool(true)
  416. Done