tags:

views:

30

answers:

2

I'm using AJAX in my site and Latin 1 characters which is indeed a problem. The solution I found was to convert accented character in html entities but i don't know how.

I'd like to transform ó, for example, in ó

I tried to use htmlentities("ó") but it printed ó. I don't know what to do anymore

Better explaining

I'm using ZF and JQuery. My site uses a form to record some data. To insert this data I use

    $data = array(
        'reg_creditorid' => $this->_request->getParam('creditor'),
        'reg_debtorid' => $this->_request->getParam('debtor'),
        'reg_reason' => htmlentities($this->_request->getParam('reason')),
        'reg_value' => str_replace(',', '.', $this->_request->getParam('value')),
        'reg_date' => date('Y-m-d')
    );
    $this->registries->insert($data);

When I tried to type ó in the text input I noticed that when I used getParam, it got ó instead of ó

I created a test project, with nothing (no ZF, no jQuery, no MVC, nothing). I coded echo htmlentities('ó'); and it printed ó. What could it be, then?

+2  A: 

Pick one character encoding (UTF-8 is a better idea than ISO-8859-1) and stick to it.

Whatever htmlentities is doing, it is treating the data as a different encoding to whatever it is actually using.

David Dorward
+2  A: 

Pass the charset you're using for your page to the htmlentities function:

htmlentities("ó",ENT_NOQUOTES,'ISO-8859-1') 
Mark Baker
it still prints ó
Rodrigo Alves
What charset is your page? What charset are you using in your htmlentities function?
Mark Baker
I solved! I just needed to use UTF-8 as the htmlentities' argument
Rodrigo Alves
I'm using ISO-8859-1 in my page but I needed to use UTF-8 as the function's argument in order to record correctly
Rodrigo Alves