简体   繁体   中英

Can't set utf8 charset in PHP

This is my php file :

<?php
  define('HOST','localhost');
  define('USER','myUser');
  define('PASS','myPass');
  define('DB','myDb');
  $con = mysqli_connect(HOST,USER,PASS,DB);
  $text = $_POST['text'];
  $name = $_POST['name'];
  $subject = $_POST['subject'];
  mysqli_set_charset($con,"utf8");
  $sql = "insert into someTable (email,text,name,subject) values ('$email','$text','$name','$subject')";
  if(mysqli_query($con,$sql)){
     echo 'Sent successfully';
  }
  else{
     echo 'Unexpected error';
  }
  mysqli_close($con);
?>

I'm sending some values from my android app to this php backend and this code will save my values to MySQL database.

It's working perfect but if i send values in non english language it shows values like this: 在此处输入图片说明

I've already set MySQL collation on UTF-8 and I think the problem is from my php backend

EDIT:

I also tried solutions in this topic but it's not working.

You had to set the collection to utf8Persian-ci . Of course I also had a problem like yours, please refer to this Link , I hope that can help you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM