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