php-src icon indicating copy to clipboard operation
php-src copied to clipboard

htmlspecialchars converts ' to #039 on PHP 8.1

Open anibalsanchez opened this issue 4 years ago • 2 comments

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

anibalsanchez avatar Dec 13 '21 20:12 anibalsanchez

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

kamil-tekiela avatar Dec 13 '21 20:12 kamil-tekiela

Thanks for the clarification.

anibalsanchez avatar Dec 13 '21 20:12 anibalsanchez