Character Special Issue

When I display the contents from the database, I get the following:

"Everyone will have a job. Others will want to. They are my people, they are my clients, and they are denied their rights.

This text was entered by the user through textarea with tinyMCE. How to replace special characters (using preg_replace ()) from a sentence with ``, with the exception of characters: <>?

+3
source share
2 answers

This article is fully noteworthy. Working with UTF-8 characters is what we all experience at some point. The trick seems to be to catch them before they enter the database or fix the database so that when they go they are not broken. Once they are there, though it's a little trickier.

+1
source

As Chuck said above, this is a database problem. If you do not want to display non-Unicode, that is, Latin characters, then yes, preg_replace is the way to go. You will need to know the character set well enough to filter out what you don't want.

But if you just want everything to display beautifully, that is, no garbage characters, then change the appropriate parts of db to accept utf-8.

. mySQL, , UTF-8. latin1_general_ci - utf8_general_ci. , .

0

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


All Articles