Page 1 of 1

I need output from database variable without the html code

Posted: Mon Sep 07, 2009 9:17 pm
by redlake2
Hi,

I am reading from a database and putting html code as well into a variable. The output includes the html code. I dont want it to.

This is what I put into my page:

<?php echo $AboutYourBusiness ?>

The output of this is:

<p>Test, Test, Test.</p> <p>Another Test, Another Test, Another Test.</p>

I don't want the output to include the <p> brackets. I store them in the database text field so that I can have the output correctly formatted over several paragraphs.

This is what I want the output to be:

Test, Test, Test.

Another Test, Another Test, Another Test.

When I look at the source of the page the brackets have been output as <p>

How can I not have the output as <p> and have it as <p>

Thanking you in advance for help.

Denise

Re: I need output from database variable without the html code

Posted: Mon Sep 07, 2009 9:21 pm
by superdezign

Code: Select all

echo htmlspecialchars_decode($AboutYourBusiness);
or

Code: Select all

echo html_entity_decode($AboutYourBusiness);
Take your pick.

Re: I need output from database variable without the html code

Posted: Mon Sep 07, 2009 9:37 pm
by Eran
Or simply don't encode your HTML as you put it in the database. Why would you be doing that?

Re: I need output from database variable without the html code

Posted: Tue Sep 08, 2009 1:05 am
by redlake2
Thanks superdezign, it works!

Pytrin, I can see your point. I didn't know that I was encoding it. It goes into an sql long text field. What am I doing wrong that encodes it?

Denise

Re: I need output from database variable without the html code

Posted: Tue Sep 08, 2009 2:06 am
by muymuy
nice post there. :)

Re: I need output from database variable without the html code

Posted: Tue Sep 08, 2009 2:36 am
by Eran
Pytrin, I can see your point. I didn't know that I was encoding it. It goes into an sql long text field. What am I doing wrong that encodes it?
Somewhere in the process an HTML encoding function is ran. It is probably htmlentities() or htmlspecialchars() - you don't need to encode data to enter it in the database, only escape it (using something mysql_real_escape_string()). Find where that encoding occurs, and remove it.

Re: I need output from database variable without the html code

Posted: Tue Sep 08, 2009 11:32 am
by redlake2
Thanks everyone, got it working. :-)