0

I've got this problem. From a source that can contains words in italian, english and some other languages. I want it to be saved in a way that I can read it after in a Wordpress site.

The problem is that I can't find a way to encode my string before saved it into the database.


Here's what I do :


$source = stripslashes($source);
$source = utf8_encode($source);
$source= mysqli_real_escape_string($con,$source);

The result on my site is something like that :

Fortune: è Apple la società più ammirata al mondo

and it should be :

Fortune: è Apple la società più ammirata al mondo

How to solve this problem?

AA Shakil
  • 538
  • 4
  • 14
Jacopo Sciampi
  • 67
  • 3
  • 13
  • 1
    what is the encoding for the field in your database structure? – Kaddath Jan 22 '18 at 11:14
  • If i remember right it should be latin-1, I've tried anyway to convert the wp-post table to utf-8, but still got this unwanted text. – Jacopo Sciampi Jan 22 '18 at 11:15
  • [mysqli_real_escape_string](https://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) can still be exploited. You should switch to [mysqli prepared statments](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) or use the api provided by wordpress [wpdb](https://developer.wordpress.org/reference/classes/wpdb/prepare/) – IsThisJavascript Jan 22 '18 at 11:16
  • Yeah, you would get this issue with latin-1. You'll only get the unwanted text if your form doesn't send the data in UTF-8. When you update the charset of a field it will still retain some messed up characters. To fix this you must convert the old values to binary and then to UTF-8 `CONVERT(CAST( as BINARY) USING utf8)` – IsThisJavascript Jan 22 '18 at 11:28

0 Answers0