Sophia_ES
Sophia_ES

Reputation: 1361

Generating HTML code in Perl to display starting HTML code?

Is there a function in PERL (don't care if it's a built-in function or a module-provided function) that will accept a string containing a section of HTML code as it's argument --- and as it's return value provide a string of newly-generated HTML code that, when sent to the browser, will show the user the same HTML code that originally was provided to this function as an argument?

For example, if the argument provided to this function is

<p>This is <em>really</em>
what I call "awesome" & then some.</p>

I would like the return-value to be something alone the lines of

&lt;p&gt;This is &lt;em&gt;really&lt;/em&gt;<br/>what
I call &quot;awesome&quot; &amp; then some.&lt;/p&gt;

So - does there exist a function in Perl that will do this for me?

Upvotes: 0

Views: 172

Answers (1)

Borodin
Borodin

Reputation: 126722

Your best choice is probably the HTML::Escape module

Use it like this

use strict;
use warnings 'all';

use HTML::Escape 'escape_html';

my $html = <<END_HTML;
<p>This is <em>really</em>
what I call "awesome" & then some.</p>
END_HTML

print escape_html($html);

output

&lt;p&gt;This is &lt;em&gt;really&lt;/em&gt;
what I call &quot;awesome&quot; &amp; then some.&lt;/p&gt;

Upvotes: 1

Related Questions