WP plugin: Entity2NCR
- plugin:
- Entity2NCR
- version:
- 0.2
- download:
- entity2ncr.zip
- source:
- entity2ncr.php
Yep, another WordPress plugin. This one has a confusing name, but should be easy to understand its purpose: it converts various HTML character entities (» & © and so on) to their numeric equivalents (» & © etc.). Many WordPress users are running afoul of character entities appearing in their comment RSS feeds, which many RSS/syndication readers fail on (also causes Firefox to get a mite testy). This should fix the problem.
Notice: WordPress 1.5.1 is now out!
If you are running 1.5.1 or above, do NOT install Entity2NCR. You don’t need it, and will run into problems due to the plugin’s function having the same name in the WordPress core. I recommend upgrading to WordPress 1.5.1 (or rather, the most recent version) instead of grabbing Entity2NCR, as it incorporates the plugin. If you’re using Entity2NCR, first deactivate it from the Plugins admin before installing 1.5.1 (delete its file from your wp-contents/plugins directory too, since it’ll just be taking up space).
To install Entity2NCR (NCR = Numeric Character Reference), download the zip file, extract entity2ncr.php from it, upload this to your wp-content/plugins/ directory, and activate the plugin in WordPress.
Along with what one might call the standard assortment of HTML character entities, Entity2NCR hits some of the unusual and obscure ones as well. Might as well. Here’s the full list, in all it’s confusing glory:
" – & – ⁄ – < – > – – ¡ – ¢ – £ – ¤ – ¥ – | (not an entity, but I’ve seen problems using it straight) – ¦ – &brkbar; – § – ¨ – ¨ – © – ª – « – ¬ – ­ – ® – ¯ – &hibar; – ° – ± – ² – ³ – ´ – µ – ¶ – · – ¸ – ¹ – º – » – ¼ – ½ – ¾ – ¿ – À – Á –  – à – Ä – Å – Æ – Ç – È – É – Ê – Ë – Ì – Í – Î – Ï – Ð – Ñ – Ò – Ó – Ô – Õ – Ö – × – Ø – Ù – Ú – Û – Ü – Ý – Þ – ß – à – á – â – ã – ä – å – æ – ç – è – é – ê – ë – ì – í – î – ï – ð – ñ – ò – ó – ô – õ – ö – ÷ – ø – ù – ú – û – ü – ý – þ – ÿ – Œ – œ – Š – š – Ÿ – ƒ – ˆ – ˜ – Α – Β – Γ – Δ – Ε – Ζ – Η – Θ – Ι – Κ – Λ – Μ – Ν – Ξ – Ο – Π – Ρ – Σ – Τ – Υ – Φ – Χ – Ψ – Ω – α – β – γ – δ – ε – ζ – η – θ – ι – κ – λ – μ – ν – ξ – ο – π – ρ – ς – σ – τ – υ – φ – χ – ψ – ω – ϑ – ϒ – ϖ –   –   –   – ‌ – ‍ – ‎ – ‏ – – – — – ‘ – ’ – ‚ – “ – ” – „ – † – ‡ – • – … – ‰ – ′ – ″ – ‹ – › – ‾ – ⁄ – € – ℑ – ℘ – ℜ – ™ – ℵ – ↵ – ⇐ – ⇑ – ⇒ – ⇓ – ⇔ – ∀ – ∂ – ∃ – ∅ – ∇ – ∈ – ∉ – ∋ – ∏ – ∑ – − – ∗ – √ – ∝ – ∞ – ∠ – ∧ – ∨ – ∩ – ∪ – ∫ – ∴ – ∼ – ≅ – ≈ – ≠ – ≡ – ≤ – ≥ – ⊂ – ⊃ – ⊄ – ⊆ – ⊇ – ⊕ – ⊗ – ⊥ – ⋅ – ⌈ – ⌉ – ⌊ – ⌋ – ⟨ – ⟩ – ← – ↑ – → – ↓ – ↔ – ◊ – ♠ – ♣ – ♥ – ♦
Phew!
Note: Entity2NCR primarily focuses on RSS output (both from posts and comments), but it can convert character entities in the regular content on your blog, as well. For this, look at the end of the plugin for the add_filter lines, and remove the comment (double-slashes at the start of a line) for any WordPress function you want to have Entity2NCR work on.
Author: Kaf Oseo
Categories: WordPress
Comments: (35) · Leave a comment · Comments RSS2 · Trackback URL
Two antlers, way up on this one!
Hi,
It seems your plugin does not recognise capitalisation. I used é (é) in my post and it matched É (É) instead, same thing for à (à) and À (À).
Trying to be as lazy as possible I tried to make your plugin recognise é (é) directly and convert it to é but with no luck, any idea if this is possible?
Yves, all I can say is: oops. Updated the file online; it’s case-sensitive now. As for any custom conversion, all you should need do is add it to the $to_ncr array. If at the end of it, make sure my final array line ends in a comma:
'♦' => '♦',This is a great idea, but what about just generating the real UTF-8 encoded characters rather than character references for those of us who are using unicode? It would probably have to be an option to generate character references for those who aren’t though.
You could have saved yourself some hours of work on compiling this list. :)
(Granted, it was a wee buggy, but I had corrected it in a later, off-b2 version (change to .phps for the source).
This functionnality was originally in WP, it just… got lost over time?
Lachlan: “This is a great idea, but what about just generating the real UTF-8 encoded characters…”
I should have no problem adding this on. The plugin could detect character encoding in use, and through that decide conversion type (NCR or literal), but I think a setting (i.e. user-changeable variable) might be the better alternative.
michel v: “You could have saved yourself some hours of work on compiling this list. :)”
That’s true…if I had spent hours compiling the list.
8)The b2vars.php does provide further outside-the-norm entities I was unaware of. I’ll glom them for Entity2NCR. And I’m not sure when this was all pulled out of WordPress; hasn’t been there since I started plugging away at it (1.2).
Thank you for this excellent plugin. It’s amazing how this wordpress community works. If one has a problem there is almost certainly someone who has solved it before or is currently working on it. Nice :-)
Does this plug-in — or any other — deal with curly quotes copied from MS Word? The writers on our blog are about double the median age of bloggers (or more ;) ), and several are writing entries in Word and then copying them over.
I know, I know. But meanwhile I need to deal with chars like “ (ampersand 8220 semi-colon, an open-curly-quote) or ” (close-quote)
These break RSS feeds. Any recommendations?
I don’t know if this plugin works for me or not? It installed no sweat, but my blogroll and newsfeed displays are still invalid. These are in my sidebar. I added “sidebar” to the filter, but I don’t think it’s working. jweaks
jweaks, I’m not seeing any problems with your feed from here. Feed Validator seems to concur.
Thanks. I’ve been playing around with my template and CSS and I got everything to validate, but I still don’t know if this plugin is doing anything? I’m leaving it activated anyway, can’t hurt. -jw
After I install your plugin and click the Activate link, I receive the following warnings in the Admin Dashboard page (header area):
Warning: Cannot modify header information - headers already sent by (output started at /home/craigran/public_html/wp-content/plugins/entity2ncr.php:300) in /home/craigran/public_html/wp-admin/admin.php on line 6
(Edited by Kaf — errors galore!)
Any assistance to resolve my issue would be greatly appreciated. This plug-in will hopefully resolve the original issue taht caused me to find and install it - lack of » element support. Thanks in advance!
Craig, that’s a common PHP error, and relates to extra spaces/lines in the script file. See this WordPress Codex page for how to fix:
http://codex.wordpress.org/Answers-Trouble_Shooting#Headers_already_sent
Or grab the zip file and extract the plugin from that (downloading from guff is fixed).
Thanks, Kaf. Downloading the Zip, which I couldn’t earlier, did the trick. My previous attempt involved copying the PHP display version into a Notepad (text) file and saving as PHP; so that must have led to the extra spaces. Thanks for the friendly reminder concerning the WP Codex. Forgot to visit that this go ’round. Appreciate your help. Nice plugin!
This function converts the vertical pipe (
|) into a broken vertical pipe (¦), which is a completely different character!You said the pipe is not an entity, but I’ve seen problems using it straight…
Thanks for catching that Mathias. I’m sure I used the correct ncr for it (|), but must have mixed things up when I was sorting the list. I’ve updated the plugin for those who haven’t made the move to 1.5.1. (!)
You’re most welcome. And I see you posted a bug report as well. Excellent!
|for president!After I have upgrade to wp 1.5.1, I got the error when I want to activate I got the error, but I forgot the message. Today, I upgraded to 0.2, I got this message:
Fatal error: Cannot redeclare ent2ncr() (previously declared in
/home/sijaya/public_html/wp-includes/functions-formatting.php:726) in
/home/sijaya/public_html/wp-content/plugins/entity2ncr.php on line 38
I have to delete the plugin in order to enter the admin area.
Jaya: running 1.5.1 you don’t need Entity2NCR, nor should you install it as 1.5.1 incorporates the plugin using the same function name which leads to the error. To deactivate it “properly” you’d need to rename the ent2ncr function in the plugin, but with it deleted I would leave things as is.
I thought the notice above was clear, but I’ll place more of a warning in it.