Posted on 2001-07-23
Medium Priority
Last Modified: 2007-11-27
Hi all,
 Hope this interests you.
I am creating an html report for the data from DB.
I wrap the data along with html to get the format.
But, what I need to make sure is that the data that
comes from db is intact like spaces,<,> etc...

So, I want to first encode the data from the DB to make it
html safe, like converting spaces into &nbsp etc...

But I dont have a built-in function for this. So,
I need to write the program. Can anybody provide the
logic for the same.(like what char are to be
turned to what chars)

Thanks in Advance.

PS:- If any body knows the equivalent function that is
available in oracle, please advise.

Question by:srinusimhadri
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3

Expert Comment

ID: 6310871
Don't change all spaces into &nbsp; !

The first question is: What characters are in the database?  Do you have control over what goes in?

Second: Any particular language you'd like used?  Perl would be fairly easy.

Author Comment

ID: 6310930
let me give an example.

1. I have an sql query like this.

   select '<tr><td>'||ename||'</td><td>'||remarks||'</td></tr>' from emp;

2. In the above example I am combining the values from the db with html. the column 'Remarks', could contain any type of characters, like special characters >,<,;,:, spaces etc.

3. Because the html does'nt recognise space as a space data like
'this   is  remarks with lot       of       spaces'
would be shown as
'this is remarks with lot of spaces'

4. And same problems with >, < and some other symbols which I dont know.

5. I dont want to make use of <pre> tag.

6. I may be using pl/sql to write that function.


Expert Comment

ID: 6310995
Sorry, I can't help with SQL.  The rest of this comment contains hints which you should consider no matter how you do the conversion.

The <pre> tag would be idea for what you want to do.  Why don't you want to use it?

Your first step MUST BE to find all characters in the database which would provide problems when mixed with HTML.  This is not as complex as it sounds.  Any decent HTML book will give you the list AND their numeric equivalents.  (Don't forget to convert the TAB character to a space.)

I've got no sympathy for wanting to NOT collapse multiple spaces  to a single space.  Please sometimes use multiple spaces to align text.  This has no place in HTML.

Good luck.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 15

Expert Comment

ID: 6312342
You're looking to do this encoding from within the database then?

Surely you are using some kind of scripting language (or equivalent) to take the data from the database and display it in the browser?


Expert Comment

ID: 6312988
Blame the typos in my earlier comment on the late hour.
"idea" should be "ideal".
"Please" should be "People".

a.marsh asks a good question.  Do you want to fix the data as it is entered into the database or when it is retrieved?  If the database is to be used for things other than generating HTML then you probably just want to leave it alone in the database and convert it solely when generating HTML.

Knowing which language you're going to use is important.

Author Comment

ID: 6342895
  I know that I have to find the characters which will give problems from the data of the database.
I know the logic. Its a very very small program.

    what are those characters???
LVL 15

Expert Comment

ID: 6343600
Well if you answer my question srinusimhadri then you may not have to worry about what the characters are!!!!!

For example, if you are using PHP there are two built-in functions that will do it all for you:




So now my question is are you using PHP??



Author Comment

ID: 6343639
No, I am going to use PL/SQL to do this.
PL/SQL is my serverside scripting lang.
Anyway,now, I came to know that such function is there(previously, I thought the same is not available which made me to post this question).

But that function encodes all characters and collapses the space characters. I want to have each &nbsp for each space in my data.

So, I want to write my own function still.

So, What are those characters.(please a.marsh 8-} )

LVL 15

Accepted Solution

a.marsh earned 200 total points
ID: 6346704
Well you have some choices - you can either convert all special characters or simply convert the ones that could possibly cause problems (hence the two different functions in PHP). I personally would go for the latter.

You can get a complete list of special characters here:


I personally would suggest only worrying about converting:

> - &gt;
< - &lt;
& - &amp;
*space* - &nbsp;



Author Comment

ID: 6346939
Great, Thats what I wanted.

Thank U a.marsh

LVL 15

Expert Comment

ID: 6347828
Glad to have helped. :o)


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question