0

I want to convert some characters before inserting them into database for example

Ž, Ć

I get data from post, and sanitize it on this whay

$ime =  (string) htmlentities(mysql_real_escape_string($data['txtIme']), ENT_COMPAT,'UTF-8', true);

In some reason I get still Ž, Š into my database

Steve
  • 1,553
  • 2
  • 20
  • 29
PhpSrbijaBgd
  • 57
  • 1
  • 11

2 Answers2

1

Depending on what you want to convert them to, mysql_set_charset() might the function you need to use. Using UTF-8 encoding, you can store most non-Standard characters, too.

However you should be careful with the mysql Extension, as it is deprecated. You should take a look at mysqli or PDO instead.

Tacticus
  • 561
  • 11
  • 24
1

From http://php.net/manual/en/function.htmlentities.php

all characters which have HTML character entity equivalents are translated into these entities

If you look at http://www.ascii.cl/htmlcodes.htm

Ž, Ć don't have HTML character entity equivalents. Š does. Which is why

<?php
     $string = 'In some reason I get still Ž, Š, Ć into my database';
     echo htmlentities($string, ENT_COMPAT,'UTF-8', true);
?>

Produces:

$ php utf.php
In some reason I get still Ž, &Scaron;, Ć into my database
sugapablo
  • 310
  • 2
  • 11