tags:

views:

51

answers:

3
$from = 'no-reply@'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8');

Especially what's ENT_COMPAT for?

Anyone knows?

A: 

forming a email address, quite stupid way

For the answer to the question Especially what's ENT_COMPAT for? you can browse PHP documentation for the htmlspecialchars, because it's this function's parameter

Col. Shrapnel
+1  A: 

htmlspecialchars encodes all characters than can be encoded as entities. This is especially important for angle brackets and ampersands. ENT_COMPAT will leave single quotes in place and only convert double quotes. 'UTF-8' will treat the input as UTF-8 encoded (instead of the default iso-latin1 encoding).

In this case, the htmlspecialchars makes only sense if the mail address will be put into a "mailto:" href attribute. Normal server names don't have characters that must be encoded, so I'm not sure if htmlspecialchars is needed.

chiborg
i doubt such an address can be used in the "mailto:" href attribute :)
Col. Shrapnel
Has anyone tested what's the value of $_SERVER['HTTP_HOST'] in case of internationalized domain names? This is the only instance where escaping could make sense
chiborg
A: 

Creating a valid looking email semi-auotmatic. The email username is 'no-reply' and the domain is whatever the servers hostname is. With a 'no-reply' the recipient usually does not reply to these emails.

ENT_COMPAT is explained here: http://php.net/manual/en/function.htmlspecialchars.php

zaf