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 best solutions below

0
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
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.