fgetss_variation2.phpt 8.8 KB

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