3

Here is my variable that I am actually getting from my MySQL Database:

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

I am using TinyMCE to format the code.

Here is how I echo it

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

Then, when I go to the page, it displays the output like this... http://i.snag.gy/BbMqx.jpg

I want the variable to make the echo formatted. So like then it will have all the html formatting.

6
  • 1
    then, what do you want to do? Commented Aug 9, 2013 at 23:03
  • Can you show what the actual output source code is? Commented Aug 9, 2013 at 23:09
  • Can you confirm that your HTML is actually stored as you said in the database? Commented Aug 9, 2013 at 23:11
  • I copied and pasted that from the DB Commented Aug 9, 2013 at 23:13
  • Does the page validate? Can you post the page source HTML? Commented Aug 9, 2013 at 23:18

2 Answers 2

2

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

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

Another solution is:

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

If the styles are to be applied to all the rows, then you could use a foreach loop:

foreach($row as $v) {

echo "<strong>$v</strong";

}

Note: This assumes that you've the mysql array result stored in a variable called $row.

It's not just for <strong tags. You can use <h1>, <p>, <div> -- it doesn't matter. PHP will output the variable content in the location you specify.

Hope this helps!

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

7 Comments

I believe this is not what the OP is looking for.
@DarrenGriffin: yes, you it will appear as bold, in this case.
I need it to process it all
I need it to process the header tags. I dont want it just to do bold, i want it to format all tags
What do you mean header tags? You can apply any style you want. Replace <strong> with the appropriate tag or use CSS. Also, if you want all elements to have the same style, you could simply insert this code in your while loop, and it'll display all elements in the required style.
|
1

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

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

Comments

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.