我对 html 实体编码有点困惑

I'm a little confused by html entity encoding

所以我知道这个

string HTML entities ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get("default_charset") [, bool $double_encode = true ]]] )

应该编码 HTML 实体,但我似乎无法让它工作。所以基本上我想问的是,有人可以向我解释如何使用它吗?

PHP 网站上的页面对我来说意义不大。

您可以使用下面的例子

$str = "Jane & 'Tarzan'";
echo htmlspecialchars($str, ENT_COMPAT); // Will only convert double quotes

$str = 'I love "PHP".';
echo htmlspecialchars($str, ENT_QUOTES); // Converts double and single quotes