Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set charset to UTF-8 in a Zend application?
    primarykey
    data
    text
    <p>I am developping a Zend application. The data in my database is encoded in "utf8_unicode_ci". I declared in my application.ini :</p> <pre><code>resources.view.encoding = "UTF-8" </code></pre> <p>but whenever I try to retrieve a String containing special characters like </p> <p>{'é', 'à', 'è',...} in the db, the string doesn't display unless I use the function : <code>utf8_decode()</code></p> <p>So I tried to set the charset to UTF-8 in :</p> <p>Bootstrap :</p> <pre><code>protected function _initDoctype() { $this-&gt;bootstrap('view'); $view = $this-&gt;getResource('view'); $view-&gt;doctype('XHTML_STRICT'); $view-&gt;setEncoding('UTF-8'); } protected function _initFrontControllerOutput() { $this-&gt;bootstrap('FrontController'); $frontController = $this-&gt;getResource('FrontController'); $response = new Zend_Controller_Response_Http; $response-&gt;setHeader('Content-Type', 'text/html; charset=UTF-8', true); $frontController-&gt;setResponse($response); $frontController-&gt;setParam('useDefaultControllerAlways', false); return $frontController; } </code></pre> <p>Layout :</p> <pre><code>$this-&gt;headMeta()-&gt;appendHttpEquiv('Content-Type', 'text/html;charset=utf8'); echo $this-&gt;headMeta(); </code></pre> <p>application.ini :</p> <pre><code>resources.view.encoding = "UTF-8" resources.db.params.charset = "utf8" </code></pre> <p>EDIT : Now I can display special chars in a page, but when I retrieve elements from the database, special chars are not displayed.</p> <ul> <li>an escaped string returns <code>null</code> (<code>$this-&gt;escape($string)</code>)</li> <li><code>echo $string</code> substitutes special chars with <code>?</code></li> </ul> <p>so I still have to use <code>utf8_decode()</code> to display them. Any suggestion ?</p> <p>thanks for your help !!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload