Email Protector

<?php
	function php_split_js_make_email($phpemail)
	{
		$pieces = explode("@", $phpemail);
	
		echo '
			<script type="text/javascript">
				var a = "<a href=\'mailto:";
				var b = "' . $pieces[0] . '";
				var c = "' . $pieces[1] .'";
				var d = "\' class=\'email\'>";
				var e = "</a>";
				document.write(a+b+"@"+c+d+b+"@"+c+e);
			</script>
			<noscript>Please enable JavaScript to view emails</noscript>
		';
	}
?>

Usage

<?php php_split_js_make_email("youremail@here.com"); ?>

Comments

  1. User Avatar
    The Frosty
    Permalink to comment#

    That’s a nice way to obscure an email. I’ve always used WordPress’ antispambot&sup1;. But for a project outside of WP…

    &sup1;http://codex.wordpress.org/Function_Reference/antispambot

  2. User Avatar
    Chester
    Permalink to comment#

    Where would I put the PHP function? Inline with the html?
    Will a PHP function run in my index.html?

    Thanks.

  3. User Avatar
    Andrew
    Permalink to comment#

    @chester – you can run php in .html files, but you might also need to enable apache via .htaccess to run php in a .html with a line like this in your .htaccess file:

    AddType application/x-httpd-php .html .htm

  4. User Avatar
    sandy
    Permalink to comment#

    i want to a php code to detach the mail from body .. please give reply..

  5. User Avatar
    djave

    I actually updated this email protector and it
    can be found here with a couple of new arguments (Same link as above)

Submit a Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

icon-closeicon-emailicon-linkicon-logo-staricon-menuicon-searchicon-staricon-tag