1

I'm saving some text into my database from a text editor.

Which looks like this in the DB:-

<p>Some text blah blah blah</p><br><p>Some more text blah blah blah blah blah blah blah</p><br><p>And even more text blah blah</p>

When I echo the the text in PHP, I just get the result above. How can i get it to use the HTML markup, instead of just printing it. For example, a '< br >' tag should create a line break instead of just printing it.

Thanks!

6
  • 2
    Question is why the markup is shown like that. This is not the default, so there has to be a reason. Please add more details and code to your question. Specifically it makes sense to shown how you output that content. Commented Jan 27, 2017 at 10:24
  • @arkascha I use TinyMCE to write the text, this is then saved into the DB with data type TEXT. I then query the DB to return an array and simply echo the text. Commented Jan 27, 2017 at 10:27
  • can you try html_entity_decode. If that works your string is saved in the database as encoded html. See w3schools.com/php/func_string_html_entity_decode.asp Commented Jan 27, 2017 at 10:27
  • That will not lead to the described behavior. Something else must come in here. Commented Jan 27, 2017 at 10:27
  • Any text editor like tinyMCE will produce html in the output. So this will be saved regardless (which i want). However, should PHP realise the HTML markup or does it just ignore and print it as text? Commented Jan 27, 2017 at 10:30

3 Answers 3

2

Use html_entity_decode():-

<?php

$string = '<p>Some text blah blah blah</p><br><p>Some more text blah blah blah blah blah blah blah</p><br><p>And even more text blah blah</p>';

echo html_entity_decode($string);

Output on my local screen:-

enter image description here

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

Comments

1

It is possible that a wring header is output. Try adding:

header('Content-Type: text/html; charset=utf-8');

Also, you can try to wrap the HTML in < html > tags.

Or maybe something adds < pre > tags around your HTML code. You should try to check the source of your output.

Comments

0

Before storing it into your database use html entity encode and when you retreive the data from the database use html entity decode. it should work

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.