http://foo.com?url= [ http://foo2.com?thing=blah ]
我想整個url的$ thing變量存儲在$ url中。如何發送url中的變量
注:支架只是爲了清楚。
http://foo.com?url= [ http://foo2.com?thing=blah ]
我想整個url的$ thing變量存儲在$ url中。如何發送url中的變量
注:支架只是爲了清楚。
$url = urlencode("http://foo2.com?thing=blah");
header("location: http://www.example.com/?url=" . $url);
根本不理解這個問題 – GolezTrol
使用PHP函數urlencode()
。
它看起來像你想要的URL的值是url http://foo2.com?thing=blah。你需要做的是使用urlencode()對該值進行編碼以安全地包含在url中。 http://php.net/manual/en/function.urlencode.php
你見過http_build_query
(還可以與http_build_url
合併)?
$data = array(
'url' => 'ttp://foo2.com?thing=blah'
);
$url = 'http://foo.com?' . http_build_query($data);
注:這些要求PECL pecl_http >= 0.23.0
+ 1,'http_build_query'在大多數時候都比'urlencode'好。如果需要添加一個新參數,它只是一個新的數組入口 - 沒有糟糕的字符串擺弄。 – vstm
誰低估了,爲什麼?此外,示例可以[在這裏找到](http://ideone.com/ndkIn)。 –
真的很不錯的解決方案。順便說一句,你真的希望有人會說「這是我」:) – Wh1T3h4Ck5
你想用urlencode像這樣:
$url = 'http://foo.com?url=' . urlencode('http://foo2.com?thing=blah');
$par = urlencode('http://foo2.com?thing=blah');
$url = 'http://foo.com?url='.$par;
不會對你投票,但是'$ link'(在你的例子中)需要被編碼,所以'?'和'='(和其他字符)不會干擾解析這個(和其他)參數。 –
@BradChristie正確!非常感謝您的反饋! 你能編輯我的答案並糾正它嗎?將不勝感激! – mongotop
看起來像[進行urlencode(HTTP工作:// PHP。 net/manual/en/function.urlencode.php) –
SO上有很多類似的問題。我建議使用會話來傳遞您的網址。 –
[PHP的URL編碼/解碼]的可能重複(http://stackoverflow.com/questions/5662249/php-url-encoding-decoding) – pilsetnieks