fgetss_variation3.phpt 11 KB

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