strings.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. // Read from the back of $haystack until $needle is found, or the begining
  15. // of the $haystack is reached.
  16. //*************************************************************************
  17. function readShortMailboxName($haystack, $needle) {
  18. if (strpos($haystack, $needle)) {
  19. $pos = strrpos($haystack, $needle) + 1;
  20. $data = substr($haystack, $pos, strlen($haystack));
  21. } else {
  22. $data = $haystack;
  23. }
  24. return $data;
  25. }
  26. // Wraps text at $wrap characters
  27. function wordWrap($passed, $wrap) {
  28. $passed = str_replace("&gt;", ">", $passed);
  29. $passed = str_replace("&lt;", "<", $passed);
  30. $words = explode(" ", trim($passed));
  31. $i = 0;
  32. $line_len = strlen($words[$i])+1;
  33. $line = "";
  34. while ($i < count($words)) {
  35. while ($line_len < $wrap) {
  36. $line = "$line$words[$i] ";
  37. $i++;
  38. $line_len = $line_len + strlen($words[$i])+1;
  39. }
  40. $line_len = strlen($words[$i])+1;
  41. if ($line_len < $wrap) {
  42. if ($i < count($words)) // don't <BR> the last line
  43. $line = "$line\n";
  44. } else {
  45. $endline = $words[$i];
  46. while ($line_len >= $wrap) {
  47. $bigline = substr($endline, 0, $wrap);
  48. $endline = substr($endline, $wrap, strlen($endline));
  49. $line_len = strlen($endline);
  50. $line = "$line$bigline<BR>";
  51. }
  52. $line = "$line$endline<BR>";
  53. $i++;
  54. }
  55. }
  56. $line = str_replace(">", "&gt;", $line);
  57. $line = str_replace("<", "&lt;", $line);
  58. return $line;
  59. }
  60. /** Returns an array of email addresses **/
  61. function parseAddrs($text) {
  62. if (trim($text) == "") {
  63. return;
  64. }
  65. $text = str_replace(" ", "", $text);
  66. $text = str_replace(",", ";", $text);
  67. $array = explode(";", $text);
  68. return $array;
  69. }
  70. /** Returns a line of comma separated email addresses from an array **/
  71. function getLineOfAddrs($array) {
  72. $to_line = "";
  73. for ($i = 0; $i < count($array); $i++) {
  74. if ($to_line)
  75. $to_line = "$to_line, $array[$i]";
  76. else
  77. $to_line = "$array[$i]";
  78. }
  79. return $to_line;
  80. }
  81. function translateText($body, $wrap_at) {
  82. /** Add any parsing you want to in here */
  83. $body = trim($body);
  84. $body_ary = explode("\n", $body);
  85. for ($i = 0; $i < count($body_ary); $i++) {
  86. $line = $body_ary[$i];
  87. $line = "^^$line";
  88. $line = str_replace(">", "&gt;", $line);
  89. $line = str_replace("<", "&lt;", $line);
  90. if (strlen($line) >= $wrap_at) // -2 because of the ^^ at the beginning
  91. $line = wordWrap($line, $wrap_at);
  92. $line = str_replace(" ", "&nbsp;", $line);
  93. $line = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $line);
  94. $line = nl2br($line);
  95. if (strpos(trim(str_replace("&nbsp;", "", $line)), "&gt;&gt;") == 2) {
  96. $line = substr($line, 2, strlen($line));
  97. $line = "<TT><FONT COLOR=FF0000>$line</FONT></TT><BR>\n";
  98. } else if (strpos(trim(str_replace("&nbsp;", "", $line)), "&gt;") == 2) {
  99. $line = substr($line, 2, strlen($line));
  100. $line = "<TT><FONT COLOR=800000>$line</FONT></TT><BR>\n";
  101. } else {
  102. $line = substr($line, 2, strlen($line));
  103. $line = "<TT><FONT COLOR=000000>$line</FONT></TT><BR>\n";
  104. }
  105. $new_body[$i] = "$line";
  106. }
  107. $bdy = implode("\n", $new_body);
  108. return $bdy;
  109. }
  110. /* SquirrelMail version number -- DO NOT CHANGE */
  111. $version = "0.3pre1";
  112. ?>