Htmlspecialchars not working

Helo

Try using htmlspecialchars but it doesn't seem to work. OSX 10.9.1 PHP 5.4.17

var_dump(htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES, 'UTF-8'));
echo htmlspecialchars("<a href='test'>Test</a>", ENT_XHTML, 'UTF-8');

and get:

string '&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;' (length=45)
<a href='test'>Test</a

Any idea? Thk.

+3
source share
1 answer

It works, but you expect something else.

The result is interpreted by your browser as HTML. You can get simple output by setting the content type to equal or using the command line.

<?php

header('Content-Type: text/plain');

var_dump(htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES, 'UTF-8'));
echo htmlspecialchars("<a href='test'>Test</a>", ENT_XHTML, 'UTF-8');
+9
source

All Articles