# HtmlEntities

Returns the string `$value`, converting characters to their corresponding HTML entity equivalents where they exist.

## Supported options for Zend_Filter_HtmlEntities

The following options are supported for `Zend_Filter_HtmlEntities`:

- quotestyle: Equivalent to the PHP htmlentities native function parameter quote_style. This allows you to define what will be done with 'single' and "double" quotes. The following constants are accepted:

  `ENT_COMPAT`, `ENT_QUOTES` `ENT_NOQUOTES` with the default being `ENT_COMPAT`.

- charset: Equivalent to the PHP htmlentities native function parameter charset. This defines the character set to be used in filtering. Unlike the PHP native function the default is 'UTF-8'. See "http://php.net/htmlentities" for a list of supported character sets.

  This option can also be set via the `$options` parameter as a `Zend_Config` object or array. The option key will be accepted as either charset or encoding.

- doublequote: Equivalent to the PHP htmlentities native function parameter double_encode. If set to false existing html entities will not be encoded. The default is to convert everything (true).

  This option must be set via the `$options` parameter or the `setDoubleEncode()` method.

## Basic usage

See the following example for the default behaviour of this filter.

    $filter = new Zend_Filter_HtmlEntities();

    print $filter->filter('<');

## Quote Style

`Zend_Filter_HtmlEntities` allows changing the quote style used. This can be useful when you want to leave double, single, or both types of quotes un-filtered. See the following example:

    $filter = new Zend_Filter_HtmlEntities(array('quotestyle' => ENT_QUOTES));

    $input  = "A 'single' and " . '"double"';
    print $filter->filter($input);

The above example returns A 'single' and "double". Notice that 'single' as well as "double" quotes are filtered.

    $filter = new Zend_Filter_HtmlEntities(array('quotestyle' => ENT_COMPAT));

    $input  = "A 'single' and " . '"double"';
    print $filter->filter($input);

The above example returns A 'single' and "double". Notice that "double" quotes are filtered while 'single' quotes are not altered.

    $filter = new Zend_Filter_HtmlEntities(array('quotestyle' => ENT_NOQUOTES));

    $input  = "A 'single' and " . '"double"';
    print $filter->filter($input);

The above example returns A 'single' and "double". Notice that neither "double" or 'single' quotes are altered.

## Helper Methods

To change or retrieve the quotestyle after instantiation, the two methods `setQuoteStyle()` and `getQuoteStyle()` may be used respectively. `setQuoteStyle()` accepts one parameter `$quoteStyle`. The following constants are accepted: `ENT_COMPAT`, `ENT_QUOTES`, `ENT_NOQUOTES`

    $filter = new Zend_Filter_HtmlEntities();

    $filter->setQuoteStyle(ENT_QUOTES);
    print $filter->getQuoteStyle(ENT_QUOTES);

To change or retrieve the charset after instantiation, the two methods `setCharSet()` and `getCharSet()` may be used respectively. `setCharSet()` accepts one parameter `$charSet`. See "http://php.net/htmlentities" for a list of supported character sets.

    $filter = new Zend_Filter_HtmlEntities();

    $filter->setQuoteStyle(ENT_QUOTES);
    print $filter->getQuoteStyle(ENT_QUOTES);

To change or retrieve the doublequote option after instantiation, the two methods `setDoubleQuote()` and `getDoubleQuote()` may be used respectively. `setDoubleQuote()` accepts one boolean parameter `$doubleQuote`.

    $filter = new Zend_Filter_HtmlEntities();

    $filter->setQuoteStyle(ENT_QUOTES);
    print $filter->getQuoteStyle(ENT_QUOTES);