Jan Robert Leegte
Jan Robert Leegte

Reputation: 47

How to escape to htmlentities except for html tags in smarty

Example:

$smarty->assign('string', '<p>Germans use "Ümlauts" and pay in €uro</p>');

{$string|escape|unescape:"html"}

results in:

<p>Germans use 'Ümlauts' and pay in €uro</p>

What am I doing wrong...

Upvotes: 1

Views: 7846

Answers (2)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111839

You should also add UTF-8 to escape function as in documentation: http://www.smarty.net/docsv2/en/language.modifier.escape

Upvotes: 1

Bjoern
Bjoern

Reputation: 16304

There are more than one reasons why this can occur.

Check the encoding of

  1. your php files,
  2. your template files and
  3. your html output (doctype and meta tags),

usually it is one of those which provokes this.

To avoid this kind of issue, in many cases the best way is to use utf8 throughout your project, which means converting smarty templates and php to utf8 and use proper utf8 tags in your html header.

HTML 4.01:

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

HTML5:

<meta charset="UTF-8">

Upvotes: 1

Related Questions