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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.