Fixed a minor MIME bug
[squirrelmail.git] / functions / strings.php
CommitLineData
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]&nbsp;";
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) {
7831268e 62 if (trim($text) == "") {
63 return;
64 }
40ee9452 65 $text = str_replace(" ", "", $text);
66 $text = str_replace(",", ";", $text);
67 $array = explode(";", $text);
68 return $array;
69 }
70
71 /** Returns a line of comma separated email addresses from an array **/
72 function getLineOfAddrs($array) {
73 $to_line = "";
74 for ($i = 0; $i < count($array); $i++) {
75 if ($to_line)
76 $to_line = "$to_line, $array[$i]";
77 else
78 $to_line = "$array[$i]";
79 }
80 return $to_line;
81 }
7ce342dc 82
78509c54 83 function translateText($body) {
84 $body = ereg_replace(" ", "&nbsp;", $body);
85 return $body;
86 }
87
7ce342dc 88 /* SquirrelMail version number -- DO NOT CHANGE */
d3cdb279 89 $version = "0.3pre1";
3302d0d4 90?>