Brian
Brian

Reputation: 121

How to literally display echo contents in php

I'm looking to literally display the contents of echo or print instead of PHP processing the HTML contained within.

For example, if I have the following: echo("<a href='$file'>$file</a> <br />\n"); the PHP parser will literally display all my files within a directory as links. What if I wanted to literally output the HTML tags without executing them so that would be displayed as plain text?

Thanks.

Upvotes: 1

Views: 729

Answers (2)

Felix
Felix

Reputation: 80

'<' = &lt; '>' = &gt;

echo ("&lt;a href='$file'&gt;$file&lt;/a&gt; &lt;br /&gt;\n");

or...

echo htmlspecialchars("<a href='$file'>$file</a> <br />\n");

Upvotes: 0

Ouerghi Yassine
Ouerghi Yassine

Reputation: 1887

Instead of echo, use php function htmlentities inside a html code tag:

echo "<code>";
echo htmlentities("<a href='$file'>$file</a> <br />\n");
echo "</code>";

Upvotes: 3

Related Questions