url_parser.php 1.4 KB

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