fgetss_variation3-win32.phpt 11 KB

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