php-src
php-src copied to clipboard
htmlspecialchars converts ' to #039 on PHP 8.1
Description
The following code:
<?php
echo htmlspecialchars("'");
Resulted in this output on PHP 8.1:
#039
But I expected this output instead (like it works on PHP 7.4 or PHP 8):
'
htmlspecialchars("'", ENT_SUBSTITUTE) makes it work on all PHP versions.
PHP Version
PHP 8.1
Operating System
No response
This is the correct behaviour. The change is documented in the changelog https://www.php.net/manual/en/function.htmlspecialchars.php Also see the migration guide https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.standard This useful blog post also explains the change https://php.watch/versions/8.1/html-entity-default-value-changes
Thanks for the clarification.