// you do character translation.
// Specifically, ' comes up as 5 characters instead of 1.
function sqWordWrap(&$line, $wrap) {
- preg_match("/^([\s>]*)([^\s>].*)$/", $line, $regs);
+ preg_match("/^([\s>]*)([^\s>].*)?$/", $line, $regs);
$beginning_spaces = $regs[1];
+ $regs[2] .= "\n";
$words = explode(" ", $regs[2]);
$i = 0;
$line = $beginning_spaces;
- if (count($words) > 1) {
- while ($i < count($words)) {
- // Force one word to be on a line (minimum)
- $line .= $words[$i];
- $line_len = strlen($beginning_spaces) + strlen($words[$i]) +
- strlen($words[$i + 1]) + 2;
- $i ++;
+ while ($i < count($words)) {
+ // Force one word to be on a line (minimum)
+ $line .= $words[$i];
+ $line_len = strlen($beginning_spaces) + strlen($words[$i]) +
+ strlen($words[$i + 1]) + 2;
+ $i ++;
- // Add more words (as long as they fit)
- while ($line_len < $wrap && $i < count($words)) {
- $line .= ' ' . $words[$i];
- $i++;
- $line_len += strlen($words[$i]) + 1;
- }
+ // Add more words (as long as they fit)
+ while ($line_len < $wrap && $i < count($words)) {
+ $line .= ' ' . $words[$i];
+ $i++;
+ $line_len += strlen($words[$i]) + 1;
+ }
- // Skip spaces if they are the first thing on a continued line
- while (!$words[$i] && $i < count($words))
- {
- $i ++;
- }
+ // Skip spaces if they are the first thing on a continued line
+ while (!$words[$i] && $i < count($words)) {
+ $i ++;
+ }
- if ($i < count($words)) {
- $line .= "\n$beginning_spaces";
- }
+ if ($i < count($words)) {
+ $line .= "\n$beginning_spaces";
}
- } else {
- $line .= $words[0];
}
}
return $bytes . '<small> ' . $type . '</small>';
}
+ /* Generates a random string from the caracter set you pass in
+ *
+ * Flags:
+ * 1 = add lowercase a-z to $chars
+ * 2 = add uppercase A-Z to $chars
+ * 4 = add numbers 0-9 to $chars
+ */
+
+ function GenerateRandomString($size, $chars, $flags = 0)
+ {
+ if ($flags & 0x1)
+ $chars .= 'abcdefghijklmnopqrstuvwxyz';
+ if ($flags & 0x2)
+ $chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ if ($flags & 0x4)
+ $chars .= '0123456789';
+
+ if ($size < 1 || strlen($chars) < 1)
+ return "";
+
+ sq_mt_randomize(); // Initialize the random number generator
+
+ while (strlen($String) < $size) {
+ $String .= $chars[mt_rand(0, strlen($chars))];
+ }
+
+ return $String;
+ }
+
?>