Jump to content

Echoing back HTML tags from MySql database to respect HTML tags?


galvin

Recommended Posts

Say I have the following text stored in a MySQL database...

 

<b>Classic Quote from movie</b>

and I retrieve it into a variable called $text, how do I properly echo that so that it keeps the bold tags and actually display the text "Classic quote from movie" in BOLD?

 

I'm doing something wrong somewhere along the line (simply doing "echo $text;") because it displays on the page as...

 

<b>Classic Quote from movie</b>

 

Instead of...

Classic Quote from movie

 

Any info on properly storing and echoing back HTML would be very appreciated.

Link to comment
Share on other sites

There's nothing specific to storing/retrieving data or php that would prevent what you are doing from working.

 

You likely have some code that is using htmlentities or htmlspecialchars on the data, which converts the < and > into html entities and they are not rendered by the browser. What does a 'view source' in your browser of the non-working <b>Classic Quote from movie</b> show?

 

 

Link to comment
Share on other sites

Thanks, after some tinkering I got it to do the bold properly.  Not really sure what I did wrong at first, but it's working as I expected now.  At one point, the code was getting echoed back into an h2 tag, so EVERYTHING was bold and that was throwing me off as well  :-\

 

Also, i noticed these strange characters in the MySQL table where the stuff is stored.  I assumed this is normal and just how MySQL stores it.  If this is bad for some reason, please let me know :)

 

<p>Prove you’re a loyal member of the team and “the leagueâ€

 

Anyway, thanks for answering!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.