[doc-en] master: docs(htmlspecialchars): add ENT_SUBSTITUTE example with invalid UTF-8 bytes (#5841)

From: Date: Mon, 07 Sep 2026 20:09:52 +0000
Subject: [doc-en] master: docs(htmlspecialchars): add ENT_SUBSTITUTE example with invalid UTF-8 bytes (#5841)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-23722@lists.php.net to get a copy of this message
Author: Louis-Arnaud (lacatoire) Committer: GitHub (web-flow) Pusher: lacatoire Date: 2026-09-07T22:09:49+02:00 Commit: https://github.com/php/doc-en/commit/a9d052e2db27dd26e5f77b13ca03f0e9d352db5a Raw diff: https://github.com/php/doc-en/commit/a9d052e2db27dd26e5f77b13ca03f0e9d352db5a.diff docs(htmlspecialchars): add ENT_SUBSTITUTE example with invalid UTF-8 bytes (#5841) Changed paths: M reference/strings/functions/htmlspecialchars.xml Diff: diff --git a/reference/strings/functions/htmlspecialchars.xml b/reference/strings/functions/htmlspecialchars.xml index d9517aea5539..1599899b51d4 100644 --- a/reference/strings/functions/htmlspecialchars.xml +++ b/reference/strings/functions/htmlspecialchars.xml @@ -247,6 +247,27 @@ $new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES); echo $new; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt; ?> +]]> + </programlisting> + </example> + </para> + <para> + <example> + <title><constant>ENT_IGNORE</constant> and <constant>ENT_SUBSTITUTE</constant> with invalid UTF-8 sequences</title> + <programlisting role="php"> +<![CDATA[ +<?php +// "\x80" is not a valid UTF-8 byte sequence. +$input = "atta\x80ck"; + +// ENT_IGNORE silently drops the invalid byte - output: "attack" +echo bin2hex(htmlspecialchars($input, ENT_QUOTES | ENT_IGNORE, 'UTF-8')), "\n"; +// 61747461636b + +// ENT_SUBSTITUTE replaces the invalid byte with U+FFFD - output: "atta" + replacement char + "ck" +echo bin2hex(htmlspecialchars($input, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')), "\n"; +// 61747461efbfbd636b +?> ]]> </programlisting> </example>

« previous php.doc.cvs (#23722) next »