mbrown122 Posted December 13, 2007 Share Posted December 13, 2007 Why cant I echo "<test>"? How can I get that string to print to the screen? Thanks.. Quote Link to comment Share on other sites More sharing options...
effigy Posted December 13, 2007 Share Posted December 13, 2007 View the source and see htmlspecialchars. Quote Link to comment Share on other sites More sharing options...
themistral Posted December 13, 2007 Share Posted December 13, 2007 echo "test"; Quote Link to comment Share on other sites More sharing options...
revraz Posted December 13, 2007 Share Posted December 13, 2007 He wants the HTML <> characters too. echo "test"; Quote Link to comment Share on other sites More sharing options...
mbrown122 Posted December 13, 2007 Author Share Posted December 13, 2007 View the source and see htmlspecialchars. That did the trick! Thanks! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 13, 2007 Share Posted December 13, 2007 That's not what the OP asked. He was wondering why he couldn't see the string "<test>" when it was echoed to the screen. The reason is that the browser sees the "<" character and assumes that then next token it find will be a tag of some sort. It will eat everything until the first ">" and not display that on the screen. If you want to see strings that start with the "<" character you have to use either the htmlspecialchars() or the htmlentities() function. Ken Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 13, 2007 Share Posted December 13, 2007 <?php echo "<"; echo "test"; echo ">"; ?> but I do not see why you cannot echo out like this: "<test>" Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 13, 2007 Share Posted December 13, 2007 When you echo any string enclosed in "< >", the browser will eat that string and not display it. The string will show in the source. Try this: <?php $str = '<test>'; echo $str . "<br>\n"; echo htmlentities($str); ?> If you display it in a browser, you will see one blank line followed by the string "<test>". If you look at the source of the web page, you will see: <test><br> <test> The first "<test>" is not shown by the browser. Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.