sikas
sikas

Reputation: 5523

php echoing angle brackets

I want to display text on the page, the text should look like this:

<sometext> ... but when I echo this, nothing appears!!

How ca I do this?

Upvotes: 2

Views: 9121

Answers (4)

Spiny Norman
Spiny Norman

Reputation: 8337

This is because the browser assumes it is an unknown tag. If you want the browser to show it, use:

echo '&lt;sometext&gt;'; 

or use the htmlentities function like so:

echo htmlentities('<sometext>');

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798814

You need to call htmlentities() to convert the HTML metacharacters into something that will display properly.

Upvotes: 0

alex
alex

Reputation: 490333

You probably want &lt;sometext&gt;.

If that text is coming from user input, you should definitely use htmlspecialchars() on it, to help prevent XSS.

Upvotes: 1

Quentin
Quentin

Reputation: 943696

A "page" is written in HTML, so < means "Start a tag".

You have to represent characters with special meaning in HTML using entities.

You can write them directly, or make use of the htmlspecialchars function.

echo "&lt;sometext&gt;";
echo htmlspecialchars("<sometext>");

Upvotes: 13

Related Questions