strings.php 1.0 KB

123456789101112131415161718192021222324252627282930
  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. $len = strlen($haystack);
  19. for ($i = $len - 1; ($i >= 0) && (!$found);$i--) {
  20. $char = $haystack[$i];
  21. if ($char == $needle)
  22. $found = 1;
  23. else
  24. $data .= $char;
  25. }
  26. return strrev($data);
  27. }
  28. ?>