strings.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. $text = str_replace(" ", "", $text);
  59. $text = str_replace(",", ";", $text);
  60. $array = explode(";", $text);
  61. return $array;
  62. }
  63. /** Returns a line of comma separated email addresses from an array **/
  64. function getLineOfAddrs($array) {
  65. $to_line = "";
  66. for ($i = 0; $i < count($array); $i++) {
  67. if ($to_line)
  68. $to_line = "$to_line, $array[$i]";
  69. else
  70. $to_line = "$array[$i]";
  71. }
  72. return $to_line;
  73. }
  74. /* SquirrelMail version number -- DO NOT CHANGE */
  75. $version = "0.1.2";
  76. ?>