php echoing angle brackets

前端 未结 4 590
有刺的猬
有刺的猬 2020-12-07 04:12

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

... but when I echo this, nothing appears!!

How ca I do thi

相关标签:
4条回答
  • 2020-12-07 04:54

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

    0 讨论(0)
  • 2020-12-07 05:09

    You probably want <sometext>.

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

    0 讨论(0)
  • 2020-12-07 05:09

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

    echo '<sometext>'; 
    

    or use the htmlentities function like so:

    echo htmlentities('<sometext>');
    
    0 讨论(0)
  • 2020-12-07 05:10

    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>");
    
    0 讨论(0)
提交回复
热议问题