43fcef5c |
1 | <? |
2 | /* URL Passing code to allow links from with in emails */ |
3 | |
4 | $url_parser_php = true; |
5 | |
6 | function replaceBlock ($in, $replace, $start, $end) { |
7 | $begin = substr($in,0,$start); |
8 | $end = substr($in,$end,strlen($in)-$end); |
9 | $ret = $begin.$replace.$end; |
10 | return $ret; |
11 | } |
12 | |
13 | function parseUrl ($body) { |
14 | #Possible ways a URL could finish. |
15 | |
16 | $poss_ends=array(" ","\n","\r","<",". "," "); |
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 | |
45 | return $body; |
46 | } |
47 | |
48 | ?> |
49 | |