HTML Entities in PHP and Java

Asked

Viewed 66 times

0

I’m using htmlentities() in PHP to store data in the database, overwriting c, ã, and other characters by HTML entities:

<?PHP
htmlentities ("Ampliação");
//Resulta na string "Amplia&ccedil;&atilde;o

In Java (Android) I need to decode these entities to their respective source values ("Magnification"), but I did not find an effective solution, only the function

Stringescapeutils.unescapeHtml4(String)

but it is converting to characters different from the originals, in addition to being depreciated.

The method

Urldecoder.Decoder(String)

Also did not result in the original string.

Any hint?

  • Why store the string doing the subtituition? It could not save the original string and when it needed to display on an html page it would make the conversion used htmlentities()?

  • After hours of trying to set up the database to accept special characters I gave up, I tried everything. PHP is set to UTF-8, in the BD I tried UTF-8, Latin1, of all kinds and nothing worked

  • I also accept response to configure the database, rather than replacing the characters

  • In this case it is better to create another question, since others looking for answers to the same question will be based on the title. In this question include as much information as possible: how you are saving in the database (code), which database, what appears when you look at the records in the database (e.g. a direct sql query in the DB and not via application), which "nothing worked" exactly, and whatever else you imagine that might help someone to help you ;-)

  • Ever tried to use Html.fromHtml((String) htmlCode).toString() ?

  • 1

    @acklay, it worked! That’s just it.

  • Just don’t need the casting inside fromHtml

Show 2 more comments

1 answer

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.