Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML::Entities encoding and single ampersand
    primarykey
    data
    text
    <p>I'm attempting to use the following line of perl, as described here: <a href="https://stackoverflow.com/questions/3054971/does-anyone-know-of-a-vim-plugin-or-script-to-convert-special-characters-to-their">Does anyone know of a vim plugin or script to convert special characters to their corresponding HTML entities?</a> - to encode HTML entities in Vim.</p> <pre><code>%!perl -p -i -e 'BEGIN { use HTML::Entities; use Encode; } $_=Encode::decode_utf8($_) unless Encode::is_utf8($_); $_=Encode::encode("ascii", $_, sub{HTML::Entities::encode_entities(chr shift)});' </code></pre> <p>It works fine (£ to &amp;pound, curly quotes etc.) except for an ampersand on it's own - &amp; - which is left as it is.</p> <p>I've tried removing the uf8 decoding, and looked at the CPAN documentation for HTML::Entities.</p> <p><strong>Answer:</strong></p> <p>@ZyX has answered the original question, but as others have pointed out in the comments, this is redundant as it's not actually necessary to use HTML entities if you are serving pages with a UTF-8 character set (which I am, both with the meta tag - </p> <pre><code>&lt;meta charset="utf-8"&gt; </code></pre> <p>and also in the Apache configuration:</p> <pre><code>AddDefaultCharset utf-8 </code></pre> <p>Indeed it's arguably a bad thing adding them in such cases; the filesize is bigger and the text is obfuscated should anyway want to make use of the source code.</p> <p>It's essential you ensure whatever editor(s) you use to create files are writing them in UTF-8 as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    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