strings.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. $words = explode(" ", trim($passed));
  29. $i = 0;
  30. $line_len = strlen($words[$i])+1;
  31. $line = "";
  32. while ($i < count($words)) {
  33. while ($line_len < $wrap) {
  34. $line = "$line$words[$i]&nbsp;";
  35. $i++;
  36. $line_len = $line_len + strlen($words[$i])+1;
  37. }
  38. $line_len = strlen($words[$i])+1;
  39. if ($line_len < $wrap) {
  40. if ($i < count($words)) // don't <BR> the last line
  41. $line = "$line<BR>";
  42. } else {
  43. $endline = $words[$i];
  44. while ($line_len >= $wrap) {
  45. $bigline = substr($endline, 0, $wrap);
  46. $endline = substr($endline, $wrap, strlen($endline));
  47. $line_len = strlen($endline);
  48. $line = "$line$bigline<BR>";
  49. }
  50. $line = "$line$endline<BR>";
  51. $i++;
  52. }
  53. }
  54. return $line;
  55. }
  56. /** Returns an array of email addresses **/
  57. function parseAddrs($text) {
  58. if (trim($text) == "") {
  59. return;
  60. }
  61. $text = str_replace(" ", "", $text);
  62. $text = str_replace(",", ";", $text);
  63. $array = explode(";", $text);
  64. return $array;
  65. }
  66. /** Returns a line of comma separated email addresses from an array **/
  67. function getLineOfAddrs($array) {
  68. $to_line = "";
  69. for ($i = 0; $i < count($array); $i++) {
  70. if ($to_line)
  71. $to_line = "$to_line, $array[$i]";
  72. else
  73. $to_line = "$array[$i]";
  74. }
  75. return $to_line;
  76. }
  77. function translateText($body) {
  78. $body = ereg_replace(" ", "&nbsp;", $body);
  79. return $body;
  80. }
  81. /* SquirrelMail version number -- DO NOT CHANGE */
  82. $version = "0.2.1";
  83. ?>