PhpSrbijaBgd PhpSrbijaBgd - 1 year ago 104
PHP Question

Escaping characters before insert into database

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

Answer Source


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

If you look at

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

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


$ php utf.php
In some reason I get still Ž, &Scaron;, Ć into my database
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download