views:

270

answers:

3

On my site www.gibberize.com if you type in the word "and" in the top textarea, the character "&" will appear in the second textarea.

The problem is that the "tweet it" link will then append the second textarea's text to a url and proceed to the link, but because it is an ampersand it will break the text.

Any solutions?

A: 

Use PHP's urlencode() function.

Franz
Oh, that's of course assuming you're using PHP. Sorry about that.
Franz
That wouldn't work anyway because conversion is all client side.
Ewan Todd
That doesn't matter. The point is that the tweet is sent in an URL.
Franz
Oops. Forgive me. That was wrong.
Franz
+2  A: 

Yes, escape the ampersand symbol before appending the tweet, change any & for %26. You may want to

encodeURIComponent()

the whole text.

Note: original function I suggested was escape().

Ast Derek
This can be done in Javascript
Ivan Nevostruev
`escape` is inappropriate for URL-encoding; EncodeURIComponent is correct. `escape` shouldn't really be used for anything.
bobince
+6  A: 

Use the encodeURIComponent function. You could just change it to %26 yourself, but it's safer to use the function provided, as that will take care of any other odd characters that might get messed up in transmission.

NickFitz
Looks like he tried this now.
Franz
also best set `element.href=` directly; don't use `setAttribute`, which is less readable and bugged in various ways in IE.
bobince