develooper Front page | perl.beginners | Postings from January 2002

RE: html entity conversion... one liner?

Thread Previous | Thread Next
From:
Bob Showalter
Date:
January 31, 2002 07:40
Subject:
RE: html entity conversion... one liner?
Message ID:
2E4528861499D41199D200A0C9B15BC031B7C9@FRISTX
> -----Original Message-----
> From: KAVANAGH, Michael [mailto:Kavanagm@oup.co.uk]
> Sent: Thursday, January 31, 2002 9:06 AM
> To: 'beginners@perl.org'
> Subject: html entity conversion... one liner?
> 
> 
> I thought it would be good to be able to do this:
> 
> $item = "<blah>";
> $item  =~ tr/<>/(&lt;)(&gt;)/;
> 
> to convert those <> symbols to their entity references.
> however, the tr operator doesn't seem to like using () to group... any
> comments on how to make this operation in to a one-liner?

In addition to all the suggestions you're getting, note that there
is the HTML::Entities module on CPAN for encoding and decoding entities.
It's part of the LWP distribution, I believe.

   use HTML::Entities;

The one-liner is then:

   encode_entities($item);

HTH

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About