I need output from database variable without the html code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
redlake2
Forum Newbie
Posts: 4
Joined: Sun Aug 17, 2008 7:34 pm
Location: Perth, Australia

I need output from database variable without the html code

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

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

Post by superdezign »

Code: Select all

echo htmlspecialchars_decode($AboutYourBusiness);
or

Code: Select all

echo html_entity_decode($AboutYourBusiness);
Take your pick.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post by Eran »

Or simply don't encode your HTML as you put it in the database. Why would you be doing that?
redlake2
Forum Newbie
Posts: 4
Joined: Sun Aug 17, 2008 7:34 pm
Location: Perth, Australia

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

Post 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
User avatar
muymuy
Forum Newbie
Posts: 2
Joined: Tue Sep 08, 2009 2:01 am

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

Post by muymuy »

nice post there. :)
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post 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.
redlake2
Forum Newbie
Posts: 4
Joined: Sun Aug 17, 2008 7:34 pm
Location: Perth, Australia

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

Post by redlake2 »

Thanks everyone, got it working. :-)
Post Reply