473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

HTML coded text from database do not display properly

2
I just added a WYSIWYG editor on my website so my users can format their content any way they want. The editor works fine and is successfully saving the html coded content on the database.

The problem is when I try to view the content, here's what it shows on the webpage:

<span style="font-family: Impact;">This is&nbsp; just a test ad only.</span><br><span style="text-decoration: line-through;">This is&nbsp; just a test ad only.</span><br><h3>This is&nbsp; just a test ad only.</h3>This is&nbsp; just a test ad only.<br><br><br><br>

The html formats do not work.

The php code to display the content is:

<?php echo nl2br(preg_replace("/\[URL\](.*)\[\/URL\]/iU", "<a href=\"\\1\" target=\"_blank\">\\1</a>$link_append", $ad['addesc'])); ?>

Can you please help me correct this code so the html coded text is displayed properly? Or, is there another way to do this?
Apr 5 '10 #1

✓ answered by Atli

Hey.

Can you show us the code that pulls the HTML from the form, saves it in the database, and finally prints it to the page?

A basic security feature in PHP is to use htmlentities or htmlspecialchars to turn HTML code into HTML-readable text, so that the HTML itself is readable instead of becoming a part of the actual HTML page.

I would guess that somewhere in the code you are using this on your HTML output. You need to locate that in your code and remove it.

If you fail to find this, you can try using the htmlspecialchars_decode() function on the outputs string just before printing it. It should revert the changes made by the previously mentioned functions. -- Note that I still recommend you try to locate the other functions and remove them. Using both is redundant; a waste of resources.

2 7610
Atli
5,058 Expert 4TB
Hey.

Can you show us the code that pulls the HTML from the form, saves it in the database, and finally prints it to the page?

A basic security feature in PHP is to use htmlentities or htmlspecialchars to turn HTML code into HTML-readable text, so that the HTML itself is readable instead of becoming a part of the actual HTML page.

I would guess that somewhere in the code you are using this on your HTML output. You need to locate that in your code and remove it.

If you fail to find this, you can try using the htmlspecialchars_decode() function on the outputs string just before printing it. It should revert the changes made by the previously mentioned functions. -- Note that I still recommend you try to locate the other functions and remove them. Using both is redundant; a waste of resources.
Apr 6 '10 #2
pgm16
2
Hi Atli,

Thank you for the advise. I tried replacing the nl2br() with htmlspecialchars_decode() and it worked perfectly!

I will try to search for the htmlentities and htmlspecialchars codes.

Thanks again...
Apr 10 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
15
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my...
9
by: Pam Ammond | last post by:
I need the code to update the database when Save is clicked and a text field has changed. This should be very easy since I used Microsoft's wizards for the OleDBAdapter and OleDBConnection, and...
5
by: David Elliott | last post by:
I need a control on a Web Page that can accept an HTML Document and will display it. Any help would be appreciated. Thanks, Dave Here is what I was trying...
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
5
by: acord | last post by:
Hi, I m getting annoying display problem when placing javascript tags in a html page. Should the javasscript tags placed at the beginning of a html page before anything start? or placed between...
6
by: john | last post by:
The standard method to transmit a file from an aspx page to a browser is to stream the file to the response then end the response. The HTML code generated by the aspx page is discarded, and the...
3
by: fjm67 | last post by:
I am new to PHP but not so new to Postgres. If someone can either direct me to some howto or even provide me with an example, I would be grateful. I would like to know if it is possible to...
1
by: andipfaff | last post by:
Hi there, I am fighting with my MysQL database in order to get french and cyrillic characters properly displayed on my website. I've created tables with latin1 charset. My Perl script on the...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.