To encode/escape all unsafe characters in a string with their HTML entities:
alias htmlencode="perl -MHTML::Entities -pe 'encode_entities(\$_)'"
alias htmldecode="perl -MHTML::Entities -pe 'decode_entities(\$_)'"
And to decode/unescape HTML entities:
$ echo "This is <b>bold</b>" | htmlencode
This is <b>bold</b>
These aliases depend on Perl and the HTML::Entities module which are standard on most modern Unixes.
$ echo "This is <b>bold</b>" | htmldecode
This is bold
See also: Web-based HTML encoder.
No comments:
Post a Comment