X10nD
X10nD

Reputation: 22050

echo the output of a <textarea> into html using php

I am echoing the below using nicedit.com

<img src=http://images/14fc272d-131b-47ce-b452-9cd47a4a3846.jpg>

<iframe width=420 height=315 src=http://www.youtube.com/embed/LBBqOTd5qzE frameborder=0 allowfullscreen></iframe>

It ends up as just as code.

I tried nl2br() but its still text.

Using htmlspecialchars()

&lt;img src=http://14fc272d-131b-47ce-b452-9cd47a4a3846.jpg&gt;<div><br></div><div><br></div><div><br></div><div>&lt;iframe width=420 height=315 src=http://www.youtube.com/embed/LBBqOTd5qzE frameborder=0 allowfullscreen&gt;&lt;/iframe&gt;</div>

Any ideas how to convert them into the said images/iframe videos etc.

Upvotes: 0

Views: 597

Answers (2)

suiz
suiz

Reputation: 377

I think you actually want to show that codes on Browser. without executing it.. It could be your solution:-

<pre>
<img src=http://images/14fc272d-131b-47ce-b452-9cd47a4a3846.jpg>

<iframe width=420 height=315 src=http://www.youtube.com/embed/LBBqOTd5qzE frameborder=0 allowfullscreen></iframe>
</pre>

Upvotes: 0

Marcin Orlowski
Marcin Orlowski

Reputation: 75645

Use htmlspecialchars() to convert special chars to entities. Also, start quoting tags' attributes:

<img src="http://images/14fc272d-131b-47ce-b452-9cd47a4a3846.jpg">
<iframe width="420" height="315" src="http://www.youtube.com/embed/LBBqOTd5qzE" frameborder="0" allowfullscreen></iframe>

You may also want to back allowfullscreen with webkitallowfullscreen mozallowfullscreen as well.

EDIT

I am echoing from <textarea>

Ok, you then already got entities (your question wasn't clear enough). You need the opposite to htmlspecialchars() then, which is html_entity_decode() or htmlspecialchars_decode()

Upvotes: 1

Related Questions