Why does echo "1<2" print 1<2 > and echo "2>1" prints 21?


#1

Why does echo "1<2" print 1<2 > and echo "2>1" print 21 ?!>

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
    <p>
    <?php
     echo "2>1";
    ?>
    </p>
    </body>
</html>

How to print "1<2"?


#2

Are you expecting a boolean?

echo 2 > 1;

#3

no. I expect a string "2>1". On other IDE it works correctly. See also topic https://discuss.codecademy.com/t/echo-adds-to-a-string/46180 the prob is the same and it is not solved yet.


#4

When < and > are printing characters, it is best to use their respective entity representations:

&lt;  and   &gt;

< and >


#5

Thanks. It works exacly I wanted to.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.