Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

About escaping strings when creating

Is a way to cancel the automatic escaping of strings? (for example, I want the users to be available to put Él hizo mucho daño; I put it in spanish to see what I'm asking for, É and ñ).

I do a validation before I insert nothing, so the security is not a problem (I think).

(EDIT: I mean when creating a new record in the db)



5.2k

Not sure that understand you. You ask about escaping, what you get on output?



18.6k

When I enter Él hizo mucho daño, the chars described in the first post are automatically escaped before inserting them on the DB (so they show up in the DB record with symbols like é).



5.2k

How you use it?

$filter = new \Phalcon\Filter();
$filter->sanitize("Él hizo mucho daño", "string");

return Él hizo mucho daño. Maybe db escaping string? You try insert string in console mode?



18.6k

Yeah, in console I update the DB putting that chars and shows perfectly. The problem is when creating the record in the controller.

Now I get a É with the sanitize() method.



5.2k

Maybe trouble with character set? Try change headers.



18.6k
Accepted
answer
edited Sep '14

Would you illuminate me setting the header? I'm trying to find how but I can't.

(EDIT: I did a workaround using the famous answer SET NAMES utf8, but I think that is a little inconvenient). (EDIT2: Putting that option now allows me to receive data from the DB without strange characters, so I think it's solved).



5.2k

header("Content-type: text/html; charset=utf-8");



18.6k

Why I would need to declare that header if i already had in the HTML <meta charset="utf-8">?

(BTW, I solved it, look up)



5.2k

You one solved it.. like this and help people :)



18.6k

Well, I didn't really solved it: Google and this post solved it http://forum.phalconphp.com/discussion/10/mysql-utf8-encoding