Posted on 2001-07-23
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
  • 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.
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.
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.


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 50 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now