开发者

php echoing angle brackets

开发者 https://www.devze.com 2023-01-30 06:29 出处:网络
I want to display text on the page, the t开发者_JAVA百科ext should look like this: <sometext> ... but when I echo this, nothing appears!!

I want to display text on the page, the t开发者_JAVA百科ext should look like this:

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

How ca I do this?


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>");


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.


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>');


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

0

精彩评论

暂无评论...
验证码 换一张
取 消