Jump to content

[SOLVED] echo "<test>" doesnt work?


mbrown122

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.