removed screen shots.. whoops.
[squirrelmail.git] / functions / strings.php
CommitLineData
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
e550d551 30 // Wraps text at $wrap_max characters
31 function wordWrap($line) {
32 $newline = $line;
33 $lastpart = $line;
34 $numlines = 0;
35 $wrap_max = 80;
36 while (strlen($lastpart) > $wrap_max) {
37 $pos = $wrap_max;
38 while ((substr($line, $pos, $pos+1) != " ") && ($pos > 0)) {
39 $pos--;
40 }
41 $before = substr($line, 0, $pos);
42 $lastpart = substr($line, $pos+1, strlen($line));
43 $newline = $before . "<BR>" . $lastpart;
44 $numlines++;
45 }
46 return $newline;
47 }
3302d0d4 48?>