url_parser.php 1.7 KB

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