PHP不想回显字符“<”和“>”

I'm trying to echo this text :

echo $string = "Hello <username> !";

But what I get is Hello !, it removed my <username>.

Do you, please, know how to fix that ?

Try this hope this will help you out. Here < and > are the part of html entities.

<?php
ini_set('display_errors', 1);
$string = "Hello <username> !";
echo $string = htmlentities($string);

Output: Hello <username> !

replace < by &lt; and > by &gt;

Try this:

echo $string = "Hello &lt;username&gt; !";

This happened because your browser treated <username> as a HTML tag, You can use htmlspecialchars

PHP:htmlspecialchars

Maybe, the php works fine.

But, when the HTML is interpreted in your browser, it goes to a username tag

Replace < and > with html entities should work.

$string = "Hello <username> !";
echo htmlentities($string);

When the < and > characters are rendered the browser interprets them as a new html tag. To prevent this from happening you should use the php htmlspecialchars() function to translate them into their html entity values ie &lt; and &gt;.

$username = htmlspecialchars("<username>");
echo $string = "Hello $username!";

http://php.net/manual/en/function.htmlspecialchars.php