PHP variable with HTML formatting

Here is my variable that I actually get from my MySQL database:

<h1>This is a H1</h1> <p>NOT BOLD</p> <p>&nbsp;</p> <p><strong>BOLD</strong></p> 

I use TinyMCE to format the code.

That's how i echo it

 <?php // WHILE LOOP GETTING $ROW FROM MYSQL $conContent = $row['content']; 

Then, when I go to the page, it displays the result as follows ... http://i.snag.gy/BbMqx.jpg

I want the variable to format the echo. So, as then, it will have all the html formatting.

+4
source share
2 answers

Can you check the source of the HTML output? Is HTML still around? It looks like strip_tags() or HTMLPurifier removes your HTML. Otherwise, you will see either the formatting applied or the output tags.

If you have HTML code in your database, you do not need to do anything with it in PHP, but you can print it directly.

+1
source

You can insert your variable in <strong> tags using the following method:

 <?php /* getting row from your table */ $conContent = $row['content']; ?> <strong> <?php echo $conContent; ?> </strong> 

Another solution:

 $conContent = $row['content']; echo "<strong>" . $conContent . "</strong"; //or echo "<strong> $conContent </strong"; 

If styles should apply to all lines, you can use the foreach loop:

 foreach($row as $v) { echo "<strong>$v</strong"; } 

Note. . It is assumed that the result of the mysql array is stored in the $row variable.

These are not just <strong tags. You can use <h1> , <p> , <div> - it does not matter. PHP will display the contents of the variable at the location you specify.

Hope this helps!

+3
source

Source: https://habr.com/ru/post/1496257/


All Articles