url_parser.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /* URL Passing code to allow links from with in emails */
  3. $url_parser_php = true;
  4. function replaceBlock ($in, $replace, $start, $end) {
  5. $begin = substr($in,0,$start);
  6. $end = substr($in,$end,strlen($in)-$end);
  7. $ret = $begin.$replace.$end;
  8. return $ret;
  9. }
  10. function parseEmail ($body) {
  11. $body = eregi_replace ("([a-z]|[0-9]|_|\.|-)+\@([a-z]|[0-9]|_|-)+(\.([a-z]|[0-9]|_|-)+)*", "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body);
  12. return $body;
  13. }
  14. function parseUrl ($body) {
  15. #Possible ways a URL could finish.
  16. $poss_ends=array(" ","\n","\r","<",".&nbsp","&nbsp");
  17. $done=False;
  18. while (!$done) {
  19. #Look for when a URL starts
  20. $where = strpos($body,"http:",$start);
  21. if ($where) {
  22. # Find the end of that URL
  23. reset($poss_ends); $end=0;
  24. while (list($key, $val) = each($poss_ends)) {
  25. $enda = strpos($body,$val,$where);
  26. if ($end == 0) $end = $enda;
  27. if ($enda < $end and $enda != 0) $end = $enda;
  28. }
  29. #Extract URL
  30. $url = substr($body,$where,$end-$where);
  31. #Replace URL with HyperLinked Url
  32. if ($url != "") {
  33. $url_str = "<a href=\"$url\" target=\"_blank\">$url</a>";
  34. # $body = str_replace($url,$url_str,$body);
  35. $body = replaceBlock($body,$url_str,$where,$end);
  36. $start = strpos($body,"</a>",$where);
  37. } else {
  38. $start = $where + 7;
  39. }
  40. } else {
  41. $done=true;
  42. }
  43. }
  44. return $body;
  45. }
  46. ?>