0

I was inserting some data on the fields of my website then i copy and pasted a string from another text editor(MS Word), then on my console log it recognizes the long single hyphen ( – ) which is the same as at PHP. But then when i execute the query the value from the database becomes different which is this:

`–`

This is the filtering that i do but as i said php recognizes it as a long hyphen ( – ) and that's the reason why they can't catch it. My question is why? Or any solution on the DB?

    $_raw_data = $_POST['edit_data'];
    $_raw_data = preg_replace('/[^A-Za-z0-9\- \'"{},:;[]]/', '', json_encode($_raw_data));
    $_raw_data = str_replace("'", "''", $_raw_data);
    $_raw_data = json_decode($_raw_data, true);
sshanzel
  • 379
  • 5
  • 18
  • 2
    What is your table charset and column collation? – Eimsas Jul 17 '17 at 08:22
  • col => latin1_swedish_ci. table => latin1_swedish_ci. Is there any settings where i can only include the common characters being used by the general people(users)? I dont really know this settings.. – sshanzel Jul 17 '17 at 08:31
  • There are 3 areas you need them to be using the same char-set, Those are the database table , the connection with the database and the viewer (the program that draws the characters e.g the browser). Why not just using [unicode](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through) and free your mind from errors like these ? – Accountant م Jul 17 '17 at 08:36
  • Yup, ise utf8mb4 as mentioned in the link which @Accountantم gave. It gives 4 bits which enough for most cases (special characters, japanese symbols, emotions and etc.) and use utf in connection – Eimsas Jul 17 '17 at 08:43

0 Answers0