开发者

How to display HTML in textarea and preserve different language characters?

开发者 https://www.devze.com 2023-02-17 20:31 出处:网络
How can I show any character encoding in a HTML text area? I currently take in a users HTML page via direct input (textarea) and then I parse it by changing href links to something else via PHP and t

How can I show any character encoding in a HTML text area?

I currently take in a users HTML page via direct input (textarea) and then I parse it by changing href links to something else via PHP and then I echo out the parsed HTML back to the user on a different page in a textarea.

However, I get s开发者_JAVA百科quare characters for chinese characters and I am wondering how I can handle this and do this for all languages or character encoding?

As a side note, I store the parsed HTML in my DB base64_encoded which works well, this was achieved with the help of SO with a previous question I had.

Thanks all for any help on how I can fix this.


If the data appears healthy in your database, the problem is not on the user input side. (verify this by accessing your database 'directly' - eg. through Sequel Pro or PHPMyAdmin - and running the data in it through a base64 de-coder).

If the data is healthy, then the reason your data isn't showing up properly in the textfield is probably because the browser is expecting text in a different encoding from the one you're sending in.

My advice: when loading the data from the database, after base64 decoding, make sure it is UTF8-encoded before you send it back to the browser, and send the following header to the browser before you output anything else:

header ('Content-type: text/html; charset=utf-8');

I hope that solves the issue for you.


i suppose the problem is when you get the data from the user make sure you are receiving data in a prober encoding.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号