I try to secure email address on my website and I used the function (twig filter) below to encode it :
/**
* The twig filter associated with this function is "encode_email"
*/
function encode_emailFilter($email)
{
$text = $email;
$text_encode = '';
for ($x=0; $x < strlen($text); $x++) {
$text_encode .= '&#x' . bin2hex($text[$x]).';';
}
return $text_encode;
}
So, I encoded my email like this
{{ emailFromDatabase|encode_email }}
And on my HTML page, it shows
supermario@gmail.com
I tried to add "raw" to the filter but, I always get the same result
{{ emailFromDatabase|raw|encode_email }}
However, if I display directly the hexadecimal without wrapping it with {{ }}
, the email address displays correctly
<span>supermario@gmail.com</span>
//Returns
[email protected]
So, what filter should I add to my twig variable to get it work?
Thanks in advance for your answers
You'll need to put
raw
at the end:{{ emailFromDatabase|encode_email|raw }}
Because you want: