0
http://www.youtube.com/watch?feature=endscreen&NR=1&v=Ahha3Cqe_fk

For some reason, the string is that. How can I change the & and make them real symbols?

Do I URL encode or decode?

Jacob
  • 75,331
  • 23
  • 142
  • 223
user847495
  • 9,143
  • 17
  • 43
  • 48

3 Answers3

1

$("<div>", {html: "http://www.youtube.com/watch?feature=endscreen&amp;NR=1&amp;v=Ahha3Cqe_fk"}).text()

or

var div = document.createElement("div");
div.innerHTML = "http://www.youtube.com/watch?feature=endscreen&amp;NR=1&amp;v=Ahha3Cqe_fk";
div.firstChild.nodeValue;
Esailija
  • 134,577
  • 23
  • 263
  • 318
0
$url=str_replace("&amp;","&",$url);

It has nothing to do with url encoding. &amp; is an HTML entity of the & symbol.

Pretty much the same deal in JS

url.replace("&amp;","&");
Adam F
  • 1,742
  • 1
  • 17
  • 18
  • 1
    So yeah I did get carried away with my PHP. – Adam F Jan 06 '12 at 00:57
  • I'll offset the negative vote, this is much better than the horde of completely irrelevant url decode answers. You want `url.replace(/&/g,"&");` though – Esailija Jan 06 '12 at 01:05
0

Create a DOM element, assign above encoded string to its innerHTML and return nodeValue.

That will be a more robust solution. If you simply want to tackle this one entity an explicit .replace() will do the trick: url.replace(/&amp;/g, "&").

Russell Dias
  • 67,406
  • 5
  • 48
  • 71