How can I decode HTML entities?

前端 未结 5 1329
自闭症患者
自闭症患者 2021-02-01 04:43

Here\'s a quick Perl question:

How can I convert HTML special characters like ü or ' to normal ASCII text?

I started

5条回答
  •  逝去的感伤
    2021-02-01 05:32

    The above answers tell you how to decode the entities into Perl strings, but you also asked how to change those into ASCII.

    Assuming that this is really what you want and you don't want all the unicode characters you can look at the Text::Unidecode module from CPAN to Zap all those odd characters back into a roughly similar collection of ASCII characters:

    use Text::Unidecode qw(unidecode);
    use HTML::Entities qw(decode_entities);
    
    my $source = '北亰';  
    print unidecode(decode_entities($source));
    
    # That prints: Bei Jing 
    

提交回复
热议问题