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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace ampesand with regular expression

Status
Not open for further replies.

jwhittlestone

Programmer
Apr 19, 2006
16
GB
Hi, I would like to remove ampersands from text and repace them with the HTML special character.

This is so that I can use them in a query string.

This is my code but it doesn't work, can you see a problem with it?

//if have needed to escape the string for previous operations

textarea.value=unescape(textarea.value);
content = textarea.value;
content = content.replace("&","&");

Thanks in adance

Jon
 
This is totally the wrong thing to do. Think about it for a minute - if you replace "&" with "&", your query string will still have an "&" in it, won't it?

You should escape your string using the "escape" function instead.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
oh yeah thanks, im such a tool! Well, I've just substituted it for "and" and then I'll do a PHP regex on the subsequent page to get the amp;

thanks..

jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top