3302d0d4 |
1 | <? |
2 | //************************************************************************* |
3 | // Count the number of occurances of $needle are in $haystack. |
4 | //************************************************************************* |
5 | function countCharInString($haystack, $needle) { |
6 | $len = strlen($haystack); |
7 | for ($i = 0; $i < $len; $i++) { |
8 | if ($haystack[$i] == $needle) |
9 | $count++; |
10 | } |
11 | return $count; |
12 | } |
13 | |
14 | //************************************************************************* |
15 | // Read from the back of $haystack until $needle is found, or the begining |
16 | // of the $haystack is reached. |
17 | //************************************************************************* |
18 | function readShortMailboxName($haystack, $needle) { |
19 | $len = strlen($haystack); |
20 | for ($i = $len - 1; ($i >= 0) && (!$found);$i--) { |
21 | $char = $haystack[$i]; |
22 | if ($char == $needle) |
23 | $found = 1; |
24 | else |
25 | $data .= $char; |
26 | } |
27 | return strrev($data); |
28 | } |
29 | |
8467bf00 |
30 | // Wraps text at $wrap characters |
31 | function wordWrap($passed, $wrap) { |
32 | $words = explode(" ", trim($passed)); |
33 | $i = 0; |
34 | $line_len = strlen($words[$i])+1; |
35 | $line = ""; |
36 | while ($i < count($words)) { |
37 | while ($line_len < $wrap) { |
38 | $line = "$line$words[$i] "; |
39 | $i++; |
40 | $line_len = $line_len + strlen($words[$i])+1; |
e550d551 |
41 | } |
8467bf00 |
42 | $line_len = strlen($words[$i])+1; |
b8ea4ed6 |
43 | if ($line_len < $wrap) { |
44 | if ($i < count($words)) // don't <BR> the last line |
45 | $line = "$line<BR>"; |
46 | } else { |
47 | $endline = $words[$i]; |
48 | while ($line_len >= $wrap) { |
49 | $bigline = substr($endline, 0, $wrap); |
50 | $endline = substr($endline, $wrap, strlen($endline)); |
51 | $line_len = strlen($endline); |
52 | $line = "$line$bigline<BR>"; |
53 | } |
54 | $line = "$line$endline<BR>"; |
55 | $i++; |
56 | } |
e550d551 |
57 | } |
8467bf00 |
58 | return $line; |
e550d551 |
59 | } |
40ee9452 |
60 | |
61 | /** Returns an array of email addresses **/ |
62 | function parseAddrs($text) { |
63 | $text = str_replace(" ", "", $text); |
64 | $text = str_replace(",", ";", $text); |
65 | $array = explode(";", $text); |
66 | return $array; |
67 | } |
68 | |
69 | /** Returns a line of comma separated email addresses from an array **/ |
70 | function getLineOfAddrs($array) { |
71 | $to_line = ""; |
72 | for ($i = 0; $i < count($array); $i++) { |
73 | if ($to_line) |
74 | $to_line = "$to_line, $array[$i]"; |
75 | else |
76 | $to_line = "$array[$i]"; |
77 | } |
78 | return $to_line; |
79 | } |
3302d0d4 |
80 | ?> |