fgetss_variation3-win32.phpt 11 KB

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