开发者

What's this PHP snippet doing?

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

Especially what's E开发者_StackOverflowNT_COMPAT for?

Anyone knows?


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜