htmlspecialchars not converting

I have this PHP code:

echo  htmlspecialchars("commen<p>commpen", ENT_QUOTES, 'UTF-8');

but it echos out this: commen<p>commpen

Unless I am wrong, that is not what it is meant to output. It should escape the <> to &lth; &gth;

The only way I have figured out to get around this is by using this header:

header('Content-type: text/plain; charset=utf-8'); 

Is there a way to do it without the header?

Answers


It is outputting &lt;. But your browser is interpreting it as the entity it is and rendering <.

Seriously, try not encoding it, see what happens.


Need Your Help

Simultaneously run Java Virtual Machines

java eclipse rcp jvm-arguments jvm-crash

I am trying to run some different Eclipse RCP implementations simultaneously, and I receive the following error message: "Java was started but returned exit code=1".

How to change font on XSSFTextBox

java apache-poi xssf

XSSFTextBox and XSSFRichTextField's

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.