PAlllUCH PAlllUCH - 5 months ago 18
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.

CODE:

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:

NICK:
a
<hr />
NICK:
asdaa
<hr />
pallluch:
cccc


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

Echo works perfectly fine with
<textarea>
, but
<hr>
doesn't seems to.

Can anyone help?

Answer

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.

Comments