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

RE: html entity conversion... one liner?

Thread Previous | Thread Next
Bob Showalter
January 31, 2002 07:40
RE: html entity conversion... one liner?
Message ID:
> -----Original Message-----
> From: KAVANAGH, Michael []
> Sent: Thursday, January 31, 2002 9:06 AM
> To: ''
> 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:



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About