-- pyarlagadda <[email protected]> wrote
(on Sunday, 30 August 2009, 04:38 PM -0700):
> I have a problem displaying the single quote on HTML using Zend Framework.
> 
> I have a string stored in MySQL database. I fetch it using Zend Framework,
> escape it using $this->escape($string) and then try to display. When I do
> that, it is shown like:
> 
> �Swiss banks�
> 
> The frist and last characters are supposed to be single quotes.
> 
> I can display it with Single Quotes without using Zend framework by directly
> connecting to MySQL and then escaping it with "htmlspecialchars" function. I
> tried to using "htmlspecialchars" after fetching the data using Zend
> framework. It simply doesn't work. 
> 
> Can somebody help me figure out what is wrong with the Zend framework while
> displaying the Single Quotes?

Most likely it's an encoding issue.

Internally, Zend_View uses htmlspecialchars() by default when you call
escape() -- but it does so using the encoding 'ISO-8859-1' (Latin-1) by
default as well. It's likely that your single quotes are stored in the
database as special characters outside the Latin-1 character set. Try
setting your view's encoding to UTF-8 to see if that corrects the issue.

You can accomplish this in a couple of ways:

 * If you are initializing Zend_View via configuration with
   Zend_Application, simply specify an "encoding" key for the View
   resource:

   resources.view.encoding = "UTF-8"

 * Manually update it prior to calling escape() by calling the
   setEncoding() method:
 
   $view->setEncoding('UTF-8');

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to