Skip to content Skip to sidebar Skip to footer

Php Obfuscating Mailto In Source With Htmlentities()

I am attempting to display email addresses on a page that function normally in a browser, but are obfuscated in code to hopefully get at least some spam bots to ignore them. I hav

Solution 1:

The misunderstanding may be from http://php.net/manual/en/function.htmlentities.php

This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

What it really means from http://php.net/manual/en/function.htmlspecialchars.php

Certain characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings.

htmlspecialchars() encodes: &, ", ', < and >. Check:

print_r(get_html_translation_table(HTML_SPECIALCHARS));

htmlentities() encodes more characters, but only characters that have special significance in HTML. Check:

print_r(get_html_translation_table(HTML_ENTITIES));

You might look at something like this. I checked it in a link and it worked as expected:

$result = preg_replace_callback('/./', function($m) {
                                           return '&#'.ord($m[0]).';';
                                       },
                                       'mailto:fake@test.com');

This replaces each character in a string with &# then the ASCII value of the character and then ;


Post a Comment for "Php Obfuscating Mailto In Source With Htmlentities()"