Disallow encoding of existing HTML objects (convert & to but not to & amp; amp;)

The data in my mysql database table has special characters such as "&".

When using then I need to convert them to &. I used htmlspecialchars to convert them to HTML objects.

But few records already have &, and he converts them to &I need them to be used as without conversion.

What to do?

+4
source share
2 answers

, . & , & &.

, & . .:)

$text = 'Your text with &s from the database';
// Decode and re-encode the special characters.
$text = htmlspecialchars(htmlspecialchars_decode($text));

(, é é), htmlspecialchars htmlentities html_entity_decode. , , .

$text = 'Your text with &s from the database';
// Decode and re-encode the special characters and other entities.
$text = htmlentities(html_entity_decode($text));

htmlspecialchars htmlentities doubleencode, , false. . , , , , - .

+2

.

& amp;, é é ..

"" HTML htmlspecialchars().

, , , , , , html .

0

Source: https://habr.com/ru/post/1609002/


All Articles