Advertisement
Guest User

Untitled

a guest
Jan 31st, 2011
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. $singleByteCharacters = str_split('abcdefghijklmnopqrstuvwxyz ');
  2. $multiByteCharacters = array('…', 'ü', 'ö', 'ä');
  3.  
  4. $imePrefs = array(
  5.     'scheme' => 'Q',
  6.     'input-charset'  => 'utf-8',
  7.     'output-charset' => 'utf-8',
  8.     'line-length' => 74,
  9.     'line-break-chars' => "\r\n",
  10. );
  11.  
  12. $errorPositions = array();
  13.  
  14. for ($strlen = 1; $strlen < 200; $strlen++) {
  15.     for ($i = 0; $i < 1000; $i++) {
  16.         $subject = '';
  17.         $multiBytePosition = rand(1, $strlen);
  18.         for ($j = 0; $j < $strlen; $j++) {
  19.             if ($j == $multiBytePosition) {
  20.                 $array = &$multiByteCharacters;
  21.             } else {
  22.                 $array = &$singleByteCharacters;
  23.             }
  24.             $index = array_rand($array);
  25.             $subject .= $array[$index];
  26.         }
  27.         $subject = substr($subject, 1);
  28.         if (!@iconv_mime_encode('subject', $subject, $imePrefs)) {
  29.             if (!isset($errorPositions[$multiBytePosition])) {
  30.                 $errorPositions[$multiBytePosition] = 0;
  31.             }
  32.             $errorPositions[$multiBytePosition]++;
  33.         }
  34.     }
  35. }
  36.  
  37. ksort($errorPositions);
  38. foreach ($errorPositions as $position => $errorCount) {
  39.     echo "$position: $errorCount\n";
  40. }
  41.  
  42. # example output:
  43. # 23: 161
  44. # 24: 238
  45. # 25: 846
  46. # 49: 1
  47. # 50: 19
  48. # 51: 47
  49. # 52: 144
  50. # 53: 264
  51. # 54: 299
  52. # 55: 119
  53. # 78: 3
  54. # 79: 5
  55. # 80: 26
  56. # 81: 44
  57. # 82: 58
  58. # 83: 111
  59. # 84: 141
  60. # 85: 149
  61. # 86: 50
  62. # 107: 1
  63. # 108: 2
  64. # 109: 4
  65. # 110: 17
  66. # 111: 22
  67. # 112: 46
  68. # 113: 60
  69. # 114: 72
  70. # 115: 72
  71. # 116: 62
  72. # 117: 32
  73. # 138: 3
  74. # 139: 1
  75. # 140: 8
  76. # 141: 15
  77. # 142: 23
  78. # 143: 31
  79. # 144: 30
  80. # 145: 23
  81. # 146: 27
  82. # 147: 21
  83. # 148: 8
  84. # 166: 1
  85. # 168: 2
  86. # 169: 1
  87. # 170: 3
  88. # 171: 5
  89. # 172: 16
  90. # 173: 10
  91. # 174: 16
  92. # 175: 9
  93. # 176: 5
  94. # 177: 15
  95. # 178: 5
  96. # 179: 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement