0

Let suppose we've database table my_code

Input

I'll create connection to this database table I'll create form with post action I'll create inside this form a textarea where i would write the input

This is example

I want

To add HTML code inside this textarea to be saved in database table my_code then i can get the HTML code applied in output page.

Output Problem

If i put the following code inside the textarea after i replaced < to &lt; and > to &gt;

This is example

Now the output when i can it from database table my_code will appears as code

This is example

While i want it appears normally as visual HTML (applied) as following

This is example

Note : someone said rather than rendering html code in the input text just put it as it < and > and yes it would appears in output just as i want but when i try to edit it in edit page will find a huge distortion where it become active as textarea inside textarea so i must rendering it but in same time i want it appears as i want.

This problems hurts me so much so any idea,keywords or solutions for it please give help, thanks.

1 Answer 1

2

Note : someone said rather than rendering html code in the input text just put it as it < and > and yes it would appears in output just as i want but when i try to edit it in edit page will find a huge distortion where it become active as textarea inside textarea so i must rendering it but in same time i want it appears as i want.

Yes. Then only apply the HTML escaping (htmlspecialchars) when you want to edit your content.

If you want to output it as raw HTML (meaning it becomes a functional <textarea>+text), then do not apply said HTML escaping.

You cannot use the same htmlescaped data for both purposes. You have to apply it depending on what you want to do with it, and best only right before you do so.

Sign up to request clarification or add additional context in comments.

2 Comments

Fine, I understood your idea and by using htmlspecialchars for example <?php $new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES); echo $new; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt; ?> Now is there any thing that can convert &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt; back to <a href='test'>Test</a>
Found, I get it back using htmlspecialchars_decode , Thanks a lot now i will read about htmlspecialchars,htmlspecialchars_decode and also htmlentities and sure i would find solution for my problem. thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.