I am having a small issue with displaying text that has been converted with htmlspecialchars. In the db I have this:
<b&amp;gt;Testing:</b&amp;gt;<br&amp;gt;<ol&amp;gt;<li&amp;gt;it&#039;s a test<br&amp;gt;</li&amp;gt;</ol&amp;gt;

When I use:

echo htmlspecialchars_decode($variable);

The page displays:
<b>Testing:</b><br><ol><li>it's a test<br></li></ol>

I am not sure why this is happening. Any help is appreciated. Thank you

Recommended Answers

All 4 Replies

Member Avatar for diafol

Not sure if the DB encoded html makes much sense - seems incomplete with ampersands all over the place. Looks double encoded. What output were you expecting?

echo htmlspecialchars_decode('&amp;');

Should give &

echo htmlspecialchars_decode("<b&amp;gt;Testing:</b&amp;gt;<br&amp;gt;<ol&amp;gt;<li&amp;gt;it&#039;s a test<br&amp;gt;</li&amp;gt;</ol&amp;gt;");

Gives me...

<b&gt;Testing:</b&gt;<br&gt;<ol&gt;<li&gt;it&#039;s a test<br&gt;</li&gt;</ol&gt;

in Browser View Source.

If you run htmlspecialchars_decode twice...

echo htmlspecialchars_decode(htmlspecialchars_decode("<b&amp;gt;Testing:</b&amp;gt;<br&amp;gt;<ol&amp;gt;<li&amp;gt;it&#039;s a test<br&amp;gt;</li&amp;gt;</ol&amp;gt;"));

I get this...

<b>Testing:</b><br><ol><li>it&#039;s a test<br></li></ol>

Which is closer to what you probably want.

I am getting <b>Testing:</b><br><ol><li>it&#039;s a test<br></li></ol>, but that is exactly what is displaying on my page. It's not showing bold text it is showing the tags.

Member Avatar for diafol

If it's showing the tags on-screen then the output is still encoded. Have a look at View Source in your browser.

That did it! Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.