2011-11-09 49 views
1

我想获得cureent网址,并通过链接发送,我卡住了。链接显示,但它缺少你混合单引号和双引号,我想包括(这里的代码示例中的内容)的URL在PHP中的变量http链接

'href' => ("http://chart.apis.google.com/chart?cht=qr&chs=300x300&choe=UTF-8&chld=H&chl='.$content .'") 

回答

1

你的报价是不正确的:

'href' => ("http://chart.apis.google.com/chart?cht=qr&chs=300x300&choe=UTF-8&chld=H&chl=".$content) 

您还应该使用进行urlencode()和urldecode(),以确保$内容变量是正确的格式

编辑 试试这个,那么:

$currentUrl = rawurlencode($_SERVER['PATH_INFO']); 
$newUrl = "http://chart.apis.google.com/chart?cht=qr&chs=300x300&choe=UTF-8&chld=H&chl="; 

header("Location: $newUrl.$currentUrl"); 

//不确定path_info是否总是包含完整的url,但是有很多函数o在网络上抓取你可以谷歌当前的网址。

+0

这些解决方案似乎都不起作用? – Dave

+0

您的原始文章看起来像一个数组的片段。 应该是$ arr = array( 'href'=>(“http://chart.apis.google.com/chart?cht=qr&chs=300x300&choe=UTF-8&chld=H&chl=".rawurlencode($content) ) );如果你想重定向到那个url,它将是 header('Location:'。$ arr ['href']);然后你可以访问变量$ arr ['href'] – fuel37

+0

谢谢 - 你的第一个解决方案很好,我把$内容设置在错误的地方。感谢您的努力。 d – Dave

3

。试试这个:

'href' => ("http://chart.apis.google.com/chart?cht=qr&chs=300x300&choe=UTF-8&chld=H&chl=".rawurlencode($content)) 
3

首先:使用urlencode

$content = urlencode($content); 

:用双引号替换你的单引号。