fork download
  1. <?php
  2.  
  3. /**
  4.  * Generate fixed-width dictionary file
  5.  *
  6.  * @author Jose Rodriguez <jose.rodriguez@exec.cl>
  7.  * @license GPLv3
  8.  * @link http://code.google.com/p/cool-php-captcha
  9.  * @package captcha
  10.  *
  11.  */
  12.  
  13.  
  14. /** Word lengths */
  15. $minLength = 5;
  16. $maxLength = 8;
  17.  
  18.  
  19.  
  20.  
  21.  
  22. if ($argc < 3) {
  23. die("Usage: $argv[0] infile outfile\n");
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30. if (!file_exists($argv[1])) {
  31. die("File '$argv[1]' doesn't exists\n");
  32. }
  33.  
  34.  
  35.  
  36. $fp = fopen($argv[1], "r");
  37. $fp2 = fopen($argv[2], "w");
  38. fwrite($fp2, "<?php /*\n");
  39.  
  40. while ($lin = fgets($fp)) {
  41. $lin = trim(strtolower($lin));
  42. $strlen = strlen($lin);
  43. if ($strlen>=$minLength && $strlen<=$maxLength && preg_match("/^[a-z]+$/", $lin)) {
  44. $lin = str_pad($lin, $maxLength);
  45. fwrite($fp2, "$lin\n");
  46. }
  47. }
  48. fwrite($fp2, "*/ ?>\n");
  49.  
  50. fclose($fp);
  51. fclose($fp2);
  52.  
  53.  
  54.  
  55. ?>
  56.  
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Usage: prog.php infile outfile