note 38703 added to function.ereg-replace
| From: | bogomil at motion-bg dot com | Date: | Sat, 03 Jan 2004 19:44:24 +0000 |
| Subject: | note 38703 added to function.ereg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62877@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.ereg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38703
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38703&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38703&report=yes
Search -- http://master.php.net/manage/user-notes.php