Textarea + special characters not showing correct

1.3k views Asked by At

I have a custom post type in my wordpress website named Office. The post type has

  • Address :: textarea
  • Telephone number :: text field
  • Fax :: text field
  • Email :: email field

When I type the following in the textarea:

This is a test
with multiple rules
Belgiƫ

He saves the following in the database:

office_address_location":"This is a testrnwith multiple rulesrnBelgiu00eb

How can I make sure he saves the correct format in the database? Or at least show the data in a correct way when I edit the textarea field.

2

There are 2 answers

0
brokekidweb On

To maintain line breaks in PHP, you can use the nl2br($string) function (documentation here). As per the PHP docs:

nl2br - Inserts HTML line breaks before all newlines in a string

In order to properly store characters with accents, you need to be using the correct charset. Try using htmlentities($text, ENT_COMPAT, 'UTF-8'); and look at the answer in this question.

0
vitr On

Here is a problem with encodings. what are the encodings of your webpage and your database table and also your database viewer? Set them all to UTF-8 if you can.