Add API to unescape HTML entities

This commit is contained in:
iliajie 2023-06-01 23:00:52 +03:00
parent b97acb1e21
commit ec21297448
No known key found for this signature in database
GPG Key ID: 121E166DD9C821AB
2 changed files with 22 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -266,6 +266,27 @@ $tmp =~ s/=/=/g;
return $tmp;
}
=head2 html_unescape(string)
Converts HTML entities to the corresponding character
=cut
sub html_unescape
{
my ($str) = @_;
if (!defined $str) {
return ''; # empty string
};
$str =~ s/&/&/g;
$str =~ s/&lt;/</g;
$str =~ s/&gt;/>/g;
$str =~ s/&quot;/"/g;
$str =~ s/&#39;/'/g;
$str =~ s/&#61;/=/g;
$str =~ s/&nbsp;/ /g;
return $str;
}
=head2 html_strip(string, replacement)
Removes any HTML from a string, replacing with nothing or given chars