2011-11-09 53 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); 

:用雙引號替換你的單引號。