fgetss_variation3.phpt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. --TEST--
  2. Test fgetss() function : usage variations - read/write modes
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip.. Not valid for Windows');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /*
  12. Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
  13. Description: Gets line from file pointer and strip HTML tags
  14. */
  15. /* try fgetss on files which are opened in read/write modes
  16. w+, w+b, w+t,
  17. a+, a+b, a+t,
  18. x+, x+b, x+t
  19. reading line by line with allowable tags: <test>, <html>, <?>
  20. */
  21. echo "*** Testing fgetss() : usage variations ***\n";
  22. /* string with html and php tags */
  23. $string_with_tags = <<<EOT
  24. <test>Testing fgetss() functions</test>
  25. <?php echo "this string is within php tag"; ?> {;}<{> this
  26. is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
  27. <html> html </html> <?php echo "php"; ?>
  28. this line is without any html and php tags
  29. this is a line with more than eighty character,want to check line splitting correctly after 80 characters
  30. this text contains some html tags <body> body </body> <br> br </br>
  31. this is the line with \n character.
  32. EOT;
  33. $filename = dirname(__FILE__)."/fgetss_variation3.tmp";
  34. /* try reading the file opened in different modes of reading */
  35. $file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+t");
  36. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  37. echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
  38. /* create an empty file and write the strings with tags */
  39. $file_handle = fopen($filename, $file_modes[$mode_counter]);
  40. fwrite($file_handle,$string_with_tags); //writing data to the file
  41. if(!$file_handle) {
  42. echo "Error: failed to open file $filename!\n";
  43. exit();
  44. }
  45. // rewind the file pointer to beginning of the file
  46. rewind($file_handle);
  47. var_dump( ftell($file_handle) );
  48. var_dump( filesize($filename) );
  49. var_dump( feof($file_handle) );
  50. /* rewind the file and read the file line by line with allowable tags */
  51. echo "-- Reading line by line with allowable tags: <test>, <html>, <?> --\n";
  52. $line = 1;
  53. while( !feof($file_handle) ) {
  54. echo "-- Line $line --\n"; $line++;
  55. var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") );
  56. var_dump( ftell($file_handle) ); // check the file pointer position
  57. var_dump( feof($file_handle) ); // check if eof reached
  58. }
  59. // close the file
  60. fclose($file_handle);
  61. // delete the file
  62. unlink($filename);
  63. } // end of for - mode_counter
  64. echo "Done\n";
  65. ?>
  66. --EXPECTF--
  67. *** Testing fgetss() : usage variations ***
  68. -- Testing fgetss() with file opened using w+ mode --
  69. int(0)
  70. int(445)
  71. bool(false)
  72. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  73. -- Line 1 --
  74. string(40) "<test>Testing fgetss() functions</test>
  75. "
  76. int(40)
  77. bool(false)
  78. -- Line 2 --
  79. string(10) " {;} this
  80. "
  81. int(99)
  82. bool(false)
  83. -- Line 3 --
  84. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  85. "
  86. int(152)
  87. bool(false)
  88. -- Line 4 --
  89. string(21) "<html> html </html>
  90. "
  91. int(193)
  92. bool(false)
  93. -- Line 5 --
  94. string(43) "this line is without any html and php tags
  95. "
  96. int(236)
  97. bool(false)
  98. -- Line 6 --
  99. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  100. int(315)
  101. bool(false)
  102. -- Line 7 --
  103. string(27) "rectly after 80 characters
  104. "
  105. int(342)
  106. bool(false)
  107. -- Line 8 --
  108. string(46) "this text contains some html tags body br
  109. "
  110. int(410)
  111. bool(false)
  112. -- Line 9 --
  113. string(23) "this is the line with
  114. "
  115. int(433)
  116. bool(false)
  117. -- Line 10 --
  118. string(12) " character. "
  119. int(445)
  120. bool(true)
  121. -- Testing fgetss() with file opened using w+b mode --
  122. int(0)
  123. int(445)
  124. bool(false)
  125. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  126. -- Line 1 --
  127. string(40) "<test>Testing fgetss() functions</test>
  128. "
  129. int(40)
  130. bool(false)
  131. -- Line 2 --
  132. string(10) " {;} this
  133. "
  134. int(99)
  135. bool(false)
  136. -- Line 3 --
  137. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  138. "
  139. int(152)
  140. bool(false)
  141. -- Line 4 --
  142. string(21) "<html> html </html>
  143. "
  144. int(193)
  145. bool(false)
  146. -- Line 5 --
  147. string(43) "this line is without any html and php tags
  148. "
  149. int(236)
  150. bool(false)
  151. -- Line 6 --
  152. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  153. int(315)
  154. bool(false)
  155. -- Line 7 --
  156. string(27) "rectly after 80 characters
  157. "
  158. int(342)
  159. bool(false)
  160. -- Line 8 --
  161. string(46) "this text contains some html tags body br
  162. "
  163. int(410)
  164. bool(false)
  165. -- Line 9 --
  166. string(23) "this is the line with
  167. "
  168. int(433)
  169. bool(false)
  170. -- Line 10 --
  171. string(12) " character. "
  172. int(445)
  173. bool(true)
  174. -- Testing fgetss() with file opened using w+t mode --
  175. int(0)
  176. int(445)
  177. bool(false)
  178. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  179. -- Line 1 --
  180. string(40) "<test>Testing fgetss() functions</test>
  181. "
  182. int(40)
  183. bool(false)
  184. -- Line 2 --
  185. string(10) " {;} this
  186. "
  187. int(99)
  188. bool(false)
  189. -- Line 3 --
  190. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  191. "
  192. int(152)
  193. bool(false)
  194. -- Line 4 --
  195. string(21) "<html> html </html>
  196. "
  197. int(193)
  198. bool(false)
  199. -- Line 5 --
  200. string(43) "this line is without any html and php tags
  201. "
  202. int(236)
  203. bool(false)
  204. -- Line 6 --
  205. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  206. int(315)
  207. bool(false)
  208. -- Line 7 --
  209. string(27) "rectly after 80 characters
  210. "
  211. int(342)
  212. bool(false)
  213. -- Line 8 --
  214. string(46) "this text contains some html tags body br
  215. "
  216. int(410)
  217. bool(false)
  218. -- Line 9 --
  219. string(23) "this is the line with
  220. "
  221. int(433)
  222. bool(false)
  223. -- Line 10 --
  224. string(12) " character. "
  225. int(445)
  226. bool(true)
  227. -- Testing fgetss() with file opened using a+ mode --
  228. int(0)
  229. int(445)
  230. bool(false)
  231. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  232. -- Line 1 --
  233. string(40) "<test>Testing fgetss() functions</test>
  234. "
  235. int(40)
  236. bool(false)
  237. -- Line 2 --
  238. string(10) " {;} this
  239. "
  240. int(99)
  241. bool(false)
  242. -- Line 3 --
  243. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  244. "
  245. int(152)
  246. bool(false)
  247. -- Line 4 --
  248. string(21) "<html> html </html>
  249. "
  250. int(193)
  251. bool(false)
  252. -- Line 5 --
  253. string(43) "this line is without any html and php tags
  254. "
  255. int(236)
  256. bool(false)
  257. -- Line 6 --
  258. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  259. int(315)
  260. bool(false)
  261. -- Line 7 --
  262. string(27) "rectly after 80 characters
  263. "
  264. int(342)
  265. bool(false)
  266. -- Line 8 --
  267. string(46) "this text contains some html tags body br
  268. "
  269. int(410)
  270. bool(false)
  271. -- Line 9 --
  272. string(23) "this is the line with
  273. "
  274. int(433)
  275. bool(false)
  276. -- Line 10 --
  277. string(12) " character. "
  278. int(445)
  279. bool(true)
  280. -- Testing fgetss() with file opened using a+b mode --
  281. int(0)
  282. int(445)
  283. bool(false)
  284. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  285. -- Line 1 --
  286. string(40) "<test>Testing fgetss() functions</test>
  287. "
  288. int(40)
  289. bool(false)
  290. -- Line 2 --
  291. string(10) " {;} this
  292. "
  293. int(99)
  294. bool(false)
  295. -- Line 3 --
  296. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  297. "
  298. int(152)
  299. bool(false)
  300. -- Line 4 --
  301. string(21) "<html> html </html>
  302. "
  303. int(193)
  304. bool(false)
  305. -- Line 5 --
  306. string(43) "this line is without any html and php tags
  307. "
  308. int(236)
  309. bool(false)
  310. -- Line 6 --
  311. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  312. int(315)
  313. bool(false)
  314. -- Line 7 --
  315. string(27) "rectly after 80 characters
  316. "
  317. int(342)
  318. bool(false)
  319. -- Line 8 --
  320. string(46) "this text contains some html tags body br
  321. "
  322. int(410)
  323. bool(false)
  324. -- Line 9 --
  325. string(23) "this is the line with
  326. "
  327. int(433)
  328. bool(false)
  329. -- Line 10 --
  330. string(12) " character. "
  331. int(445)
  332. bool(true)
  333. -- Testing fgetss() with file opened using a+t mode --
  334. int(0)
  335. int(445)
  336. bool(false)
  337. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  338. -- Line 1 --
  339. string(40) "<test>Testing fgetss() functions</test>
  340. "
  341. int(40)
  342. bool(false)
  343. -- Line 2 --
  344. string(10) " {;} this
  345. "
  346. int(99)
  347. bool(false)
  348. -- Line 3 --
  349. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  350. "
  351. int(152)
  352. bool(false)
  353. -- Line 4 --
  354. string(21) "<html> html </html>
  355. "
  356. int(193)
  357. bool(false)
  358. -- Line 5 --
  359. string(43) "this line is without any html and php tags
  360. "
  361. int(236)
  362. bool(false)
  363. -- Line 6 --
  364. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  365. int(315)
  366. bool(false)
  367. -- Line 7 --
  368. string(27) "rectly after 80 characters
  369. "
  370. int(342)
  371. bool(false)
  372. -- Line 8 --
  373. string(46) "this text contains some html tags body br
  374. "
  375. int(410)
  376. bool(false)
  377. -- Line 9 --
  378. string(23) "this is the line with
  379. "
  380. int(433)
  381. bool(false)
  382. -- Line 10 --
  383. string(12) " character. "
  384. int(445)
  385. bool(true)
  386. -- Testing fgetss() with file opened using x+ mode --
  387. int(0)
  388. int(445)
  389. bool(false)
  390. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  391. -- Line 1 --
  392. string(40) "<test>Testing fgetss() functions</test>
  393. "
  394. int(40)
  395. bool(false)
  396. -- Line 2 --
  397. string(10) " {;} this
  398. "
  399. int(99)
  400. bool(false)
  401. -- Line 3 --
  402. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  403. "
  404. int(152)
  405. bool(false)
  406. -- Line 4 --
  407. string(21) "<html> html </html>
  408. "
  409. int(193)
  410. bool(false)
  411. -- Line 5 --
  412. string(43) "this line is without any html and php tags
  413. "
  414. int(236)
  415. bool(false)
  416. -- Line 6 --
  417. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  418. int(315)
  419. bool(false)
  420. -- Line 7 --
  421. string(27) "rectly after 80 characters
  422. "
  423. int(342)
  424. bool(false)
  425. -- Line 8 --
  426. string(46) "this text contains some html tags body br
  427. "
  428. int(410)
  429. bool(false)
  430. -- Line 9 --
  431. string(23) "this is the line with
  432. "
  433. int(433)
  434. bool(false)
  435. -- Line 10 --
  436. string(12) " character. "
  437. int(445)
  438. bool(true)
  439. -- Testing fgetss() with file opened using x+b mode --
  440. int(0)
  441. int(445)
  442. bool(false)
  443. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  444. -- Line 1 --
  445. string(40) "<test>Testing fgetss() functions</test>
  446. "
  447. int(40)
  448. bool(false)
  449. -- Line 2 --
  450. string(10) " {;} this
  451. "
  452. int(99)
  453. bool(false)
  454. -- Line 3 --
  455. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  456. "
  457. int(152)
  458. bool(false)
  459. -- Line 4 --
  460. string(21) "<html> html </html>
  461. "
  462. int(193)
  463. bool(false)
  464. -- Line 5 --
  465. string(43) "this line is without any html and php tags
  466. "
  467. int(236)
  468. bool(false)
  469. -- Line 6 --
  470. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  471. int(315)
  472. bool(false)
  473. -- Line 7 --
  474. string(27) "rectly after 80 characters
  475. "
  476. int(342)
  477. bool(false)
  478. -- Line 8 --
  479. string(46) "this text contains some html tags body br
  480. "
  481. int(410)
  482. bool(false)
  483. -- Line 9 --
  484. string(23) "this is the line with
  485. "
  486. int(433)
  487. bool(false)
  488. -- Line 10 --
  489. string(12) " character. "
  490. int(445)
  491. bool(true)
  492. -- Testing fgetss() with file opened using x+t mode --
  493. int(0)
  494. int(445)
  495. bool(false)
  496. -- Reading line by line with allowable tags: <test>, <html>, <?> --
  497. -- Line 1 --
  498. string(40) "<test>Testing fgetss() functions</test>
  499. "
  500. int(40)
  501. bool(false)
  502. -- Line 2 --
  503. string(10) " {;} this
  504. "
  505. int(99)
  506. bool(false)
  507. -- Line 3 --
  508. string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
  509. "
  510. int(152)
  511. bool(false)
  512. -- Line 4 --
  513. string(21) "<html> html </html>
  514. "
  515. int(193)
  516. bool(false)
  517. -- Line 5 --
  518. string(43) "this line is without any html and php tags
  519. "
  520. int(236)
  521. bool(false)
  522. -- Line 6 --
  523. string(79) "this is a line with more than eighty character,want to check line splitting cor"
  524. int(315)
  525. bool(false)
  526. -- Line 7 --
  527. string(27) "rectly after 80 characters
  528. "
  529. int(342)
  530. bool(false)
  531. -- Line 8 --
  532. string(46) "this text contains some html tags body br
  533. "
  534. int(410)
  535. bool(false)
  536. -- Line 9 --
  537. string(23) "this is the line with
  538. "
  539. int(433)
  540. bool(false)
  541. -- Line 10 --
  542. string(12) " character. "
  543. int(445)
  544. bool(true)
  545. Done