将 php 变量传递给 window.location


Passing php variable to window.location

我使用以下代码作为我的sumbit到reddit按钮。

onclick="window.location = 'http://www.reddit.com/submit?url=<?php echo $url?>';

但上述内容不适用于'的情况$url

onclick="window.location = 'http://www.reddit.com/submit?url=http://vinejar.com/96-Don't-be-this-guy.html';

有必要$url那里,所以以下内容无济于事。

onclick="window.location = 'http://www.reddit.com/submit?url=' + encodeURIComponent(window.location);

您可以对$url进行编码,例如:

onclick="window.location = 'http://www.reddit.com/submit?url=<?php echo urlencode($url) ?>';