Javascript URL编码字符串就像谷歌在Chrome中做的那样

Javascript URL编码字符串就像谷歌在Chrome中做的那样,javascript,php,curl,encoding,Javascript,Php,Curl,Encoding,我有一个URL需要在PHP中卷曲: http://query.yahooapis.com/v1/public/yql?q= select * from yahoo.finance.historicaldata where symbol = "LINE" and startDate = "2015-09-23" and endDate = "2015-09-25" &format=xml &env=store://datatables.org/alltableswithkeys

我有一个URL需要在PHP中卷曲:

http://query.yahooapis.com/v1/public/yql?q= select * from yahoo.finance.historicaldata where symbol = "LINE" and startDate = "2015-09-23" and endDate  = "2015-09-25" &format=xml &env=store://datatables.org/alltableswithkeys
当我使用URL“原样”时,我什么也得不到,没有数据,空白页

当我在Chrome的地址栏中输入URL时,我会得到一些编码,URL如下所示:

http://query.yahooapis.com/v1/public/yql?q=%20select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20=%20%22LINE%22%20and%20startDate%20=%20%222015-09-23%22%20and%20endDate%20=%20%222015-09-25%22%20&format=xml%20&env=store://datatables.org/alltableswithkeys
现在,当我把这个URL卷曲到它上面时,我得到了数据。 问题是,我需要以编程方式执行此操作,而不是复制/粘贴。因此,我使用了
rawurlencode
urlencode
,但它们不会像上面那样转换URL,我再次得到一个空白页面


我应该使用什么类型的编码(最好是PHP,但javascript也不错)来像Google Chrome那样转换URL

如果使用Javascript,您可以使用:

document.querySelector('div')。textContent=encodeURI('div')http://query.yahooapis.com/v1/public/yql?q= 从yahoo.finance.historicaldata中选择*,其中symbol=“LINE”和startDate=“2015-09-23”和endDate=“2015-09-25”&format=xml&env=store://datatables.org/alltableswithkeys');

所以我使用了rawurlencode和urlencode-你只在查询字符串的参数上应用了它吗?@Leggendario我在整个URL上使用了它,但不起作用,然后我只在参数上使用了它,这也不起作用。我在整个URL上使用了它-这是一个错误。然后我只在参数上使用了它-你是怎么做到的?@Leggendario这没关系。有很多参数,我必须把它分成十块左右。我在寻找一个更通用的方法,将采取整个网址。问题是(我想)双引号和相等符号也被编码了,这就是产生问题的原因。如果你说“没关系”,我们怎么回答你?让我们来看看您是如何编码uri的。您可能想使用以下内容:非常感谢:)有没有关于如何在PHP中实现这一点的想法?我在这里做一些研究,但我从未使用过PHP,对不起:(@user2604269看一下这种方法:-以更多票数给出答案的家伙在PHP中创建了一个助手函数,其行为与Javascript的
encodeURI
相同。