Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting HTML entities

Status
Not open for further replies.

Foamcow

Programmer
Nov 14, 2002
6,092
GB
Is there a quick and easy way to convert a string containing & , < and > characters to their corresponding HTML entities using ASP classic?

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
It may well do, but is that only specific to .Net or could it be used in 'Classic' ASP?

I'm a PHP chap normally, just trying to help someone out.

The main problem was & characters so I'm just using
Code:
str = Replace(str,"&","&amp;",1,-1,1)

It's working ok, not sure about performance, but it would be good to know if there was a nice built in way to do this in ASP classic.

PHP has the built in htmlentities() function which does exactly what I need.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
It is for classic asp exposed through vbs and/or jscript script engine.
 
Ah yes, thanks.
That works.

Thinking on it further though I realised that some of the content I need to parse contains HTML. What I really need to do is just convert ampersands and instances of > and < that aren't part of tags.

I think, in this case, that using Replace is going to suffice.

Thanks for the help

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
I actually think your going to need to use a regular expression or three. Replace isn't going to be smart enough to know whether your lt's or gt's are part of tags or just hanging out in the middle of a paragraph of text all by themselves.

Best MS KB Ever:
 
Further inspection revealed that I don't need to do anything with the < and >. It's just ampersands and possibly some apostrophes and quote marks.

I don't really need HTML entity conversion as I first thought I did.



<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top