PAlllUCH PAlllUCH - 1 year ago 105
PHP Question

Echo a XHTML tag

When I try to echo most of XTHML tags inside a PHP loop which one echo's data from a MySQL it just shows text in browser. I'm running XAMPP Control Panel with Apache and MySQL for tests.


echo "<textarea readonly>";
while ($wiersz = mysql_fetch_array($sql_wynik_zapytania))
echo " ".$wiersz['NICK'].":\n";
echo $wiersz['KOMENT']."\n"."<hr />"."\n";
echo "</textarea>";

The results in browser:

<hr />
<hr />

"a" "asdaa" "cccc" are just random texts added to table in databse for tests.

Echo works perfectly fine with
, but
doesn't seems to.

Can anyone help?

Answer Source

A textarea element can't contain anything other than plain text.

You are writing invalid HTML and the browser is trying to recover by treating the < character as plain text instead of the start of a tag.

It looks like you aren't using the textarea to accept user input anyway (you've made it readonly). Don't use a textarea element here. You probably want to use <pre> instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download