note 38703 deleted from function.ereg-replace by didou
| From: | didou@php.net | Date: | Tue, 18 May 2004 13:17:01 +0000 |
| Subject: | note 38703 deleted from function.ereg-replace by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69756@lists.php.net to get a copy of this message | ||
Note Submitter: bogomil@motion-bg.com
----
I'm really getting tired of spammers, so here's a nice solution for all of you to stop
spam spiders crawling your sites and collecting your e-mail addresses.
Please note, that I'm quite new to using regular expressions, so I used another example and
modified it to work for me. There could be errors - I can't guarantee that it will work
correctly always, but it works for me.
$myemail = 'test@testdomain.com';
$output_email = ereg_replace ('([_a-zA-z0-9\-]+(\.[_a-zA-z0-9\-]+)*)\@
([_a-zA-z0-9\-]{1,})+(\.[a-zA-z]{1,3})+', '<script>var a,b,c,d,e;a=\'<a
href="mai\';b = \'\1\';c = \'\">\';a+= \'lto:\';b+=
\'@\';e = \'</a>\';b+=
\'\3\4\';document.write(a+b+c+b+e);</script>', $myemail);
This will output a javascript code that will produce correct html output for the browser to
correctly handle e-mail mailto: links, but still making them
"invisible" to spam spiders!
Here's the result:
<script>var a,b,c,d,e;a='<a href="mai';b = 'test';c =
'\">';a+= 'lto:';b+= '@';e = '</a>';b+=
'testdomain.com';document.write(a+b+c+b+e);</script>
E.g. from the browser's point of view this is interpreted as a normal <a href="mailto:test@testdomain.com">test@testdomain.com</a>
You can see it working in reality at http://www.motion-hosting.com (it has been formatted to
look nice there).
Hope this helps you to prevent spam/junk mail getting in your inbox!
Best Regards: Bogomil Alexandrov