Location: PHPKode > scripts > E-Mail Encoder Class > e-mail-encoder-class/email_encoder_class.php
<?php 
class email {

var $email;
var $cryptet_email;
var $link_text;
var $css_class;

function emailcrypter($email) {
	$crypt_email="";
	$max_zeichen=strlen($email);
		for ($i=0; $i<$max_zeichen;$i++) {
		$zeichen=substr($email,$i,1);
		$ascii_wert=ord($zeichen);
		$crypt_email.="&#".$ascii_wert.";";
		}
	return $crypt_email;	 
}

function output ($cryptet_email,$link_text,$css_class) {
	if ($link_text == "") {
		$link_text = $cryptet_email;
	}
	echo "<a href=\"mailto:".$cryptet_email."\"";
	if ($css_class != "") {
		echo " class=\"".$css_class."\"";
	}
	echo ">".$link_text."</a>";
}

function output_var ($cryptet_email,$link_text,$css_class) {
	if ($link_text == "") {
		$link_text = $cryptet_email;
	}
	$output_var="<a href=\"mailto:".$cryptet_email."\"";
	if ($css_class != "") {
	$output_var.=" class=\"".$css_class."\"";
	}
	$output_var.=">".$link_text."</a>";
	return $output_var;
}
	
function replace_in_text ($text,$css_class) {
	$find_email="/([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si";
	//$find_email="/^([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si";
	preg_match_all($find_email, $text, $mail_matches);
	//print_r ($mail_matches[0]);
	for ($m=0; $m<count($mail_matches[0]); $m++) {
		$crypt_email[$m]="";
		$max_zeichen[$m]=strlen($mail_matches[0][$m]);
			for ($i=0; $i<$max_zeichen[$m];$i++) {
			$zeichen[$m]=substr($mail_matches[0][$m],$i,1);
			$ascii_wert[$m]=ord($zeichen[$m]);
			$crypt_email[$m].="&#".$ascii_wert[$m].";";
			}
		$output_var[$m]="<a href=\"mailto:".$crypt_email[$m]."\"";
		if ($css_class != "") {
		$output_var[$m].=" class=\"".$css_class."\"";
		}
		$output_var[$m].=">".$crypt_email[$m]."</a>";
		//$text = preg_replace($find_email, $output_var[$k], $text);
		$text = str_replace($mail_matches[0][$m], $output_var[$m], $text); 
	}
	$text = eregi_replace("http://www.", "www.", $text);
	$text = eregi_replace("www.", "http://www.", $text);
	//$find_url="#(^|[^\"=]{1})(http://)([^\s<>]+)([\s\n<>]|$)#sm";
	$find_url="#(http://)([^\s<>]+)#sm";
	preg_match_all($find_url, $text, $url_matches);
	for ($u=0; $u<count($url_matches[0]); $u++) {
		$url_output_var[$u]="<a href=\"".$url_matches[0][$u]."/\"";
		if ($css_class != "") {
		$url_output_var[$u].=" class=\"".$css_class."\"";
		}
		$url_output_var[$u].=" target=\"_blank\">";
		$url_output_var[$u].=$url_matches[0][$u];
		$url_output_var[$u].="</a>";
		$text = str_replace($url_matches[0][$u], $url_output_var[$u], $text);
		$text = str_replace("http://www.", "www.", $text);
	}
	return $text;
}

}
?>
Return current item: E-Mail Encoder Class