At 18:52 +0800 03/02/2011, Jeff Pang wrote:

2011/2/2 Shlomit Afgin <[email protected]>:


 > I tried to convert html special characters to their real character.
 > For example, converting    &#8221;      to     "   .
 >
 > I had the string
 > $str = "&#8220; test &#8221; ÈÒÈÂÔ†¢ª
 > The string contain also Hebrew letters.

Could Encode work on it?

use Encode;
$new = encode("iso-8859-1",decode("iso-8859-8",$str));

Heaven forbid!

The html entities are Unicode decimal, so all you need to do in this case is get the number n and then execute chr n in a substitution:


#!/usr/local/bin/perl
use strict;
binmode STDOUT, 'utf8';
$_ = "&#8220;&#1488;&#8221;";
s~&#([\d]+);~chr $1~eg;
print; # -=>  “א”

JD

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to